'if error in useEffect, return <NotFound/>

Below I want to use a variable to record error condition of useEffect, and handle it later on. Is it good to use a useState variable, or there are more suitable method then that?

const [isWorkspaceExist, setIsWorkspaceExist] = useState(true); //<- the variable from usestate
useEffect(() => {
    router.query.id &&
    Promise.all([getProjects(router.query.id), getMembers(router.query.id)]).then(
        ([allProjects, allMembers]) => {
            console.log(allProjects);
            console.log(allMembers);

            
        }
    ).catch(() => {
        setIsWorkspaceExist(false); //<- record it
    });
}, [router.query.id]);

if (!isWorkspaceExist) { //<- if error shows not found
    return <NotFound/>;
}else{
    return <MyWebPage/>
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source