Skip to content

Commit

Permalink
fixed solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
OkMoroz committed Dec 19, 2024
1 parent 07d4452 commit 4c3d32c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
16 changes: 7 additions & 9 deletions src/AppWithContexts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@ export const AppWithContexts: React.FC = () => {
const [selectedPost, setSelectedPost] = useState<Post | null>(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 (
Expand Down
4 changes: 1 addition & 3 deletions src/context/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { User } from '../types/User';
type SetUserContextType = React.Dispatch<React.SetStateAction<User | null>>;

export const UserContext = createContext<User | null>(null);
export const SetUserContext = createContext<SetUserContextType | undefined>(
undefined,
);
export const SetUserContext = createContext<SetUserContextType>(() => {});

type Props = {
children: React.ReactNode;
Expand Down

0 comments on commit 4c3d32c

Please sign in to comment.