diff --git a/src/AppWithContexts.tsx b/src/AppWithContexts.tsx index 2260fabb3..ec16956ef 100644 --- a/src/AppWithContexts.tsx +++ b/src/AppWithContexts.tsx @@ -20,20 +20,18 @@ export const AppWithContexts: React.FC = () => { const [selectedPost, setSelectedPost] = useState(null); useEffect(() => { - if (!selectedUser) { - return; - } - setPosts([]); setError(false); setIsLoading(true); - setSelectedPost(null); + if (selectedUser) { + setSelectedPost(null); - getPosts(selectedUser.id) - .then(setPosts) - .catch(() => setError(true)) - .finally(() => setIsLoading(false)); + getPosts(selectedUser.id) + .then(setPosts) + .catch(() => setError(true)) + .finally(() => setIsLoading(false)); + } }, [selectedUser]); return ( diff --git a/src/context/UserContext.tsx b/src/context/UserContext.tsx index b2fbbccdf..dd68600a7 100644 --- a/src/context/UserContext.tsx +++ b/src/context/UserContext.tsx @@ -4,9 +4,7 @@ import { User } from '../types/User'; type SetUserContextType = React.Dispatch>; export const UserContext = createContext(null); -export const SetUserContext = createContext( - undefined, -); +export const SetUserContext = createContext(() => {}); type Props = { children: React.ReactNode;