constitutional-coralC
Refine2y ago
3 replies
constitutional-coral

Issues with remix and useGo with remix router

I have the following error: Cannot update a component (RouterProvider) while rendering a different component (Index). To locate the bad setState() call inside Index, follow the stack trace as described in some of _root.tsx: ``` import '@fontsource-variable/manrope'; import {Refine} from "@refinedev/core"; import {authProvider} from "~/data/auth-provider.js"; import routerProvider from "@refinedev/remix-router"; export const links: LinksFunction = () => [ {rel: "stylesheet", href: stylesheet}, ]; export function Layout({children}: { children: React.ReactNode }) { return ( <html lang="en"> <head> <meta charSet="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <Meta/> <Links/> </head> <body> {children} <ScrollRestoration/> <Scripts/> </body> </html> ); } export default function App() { return ( <Refine authProvider={authProvider} routerProvider={routerProvider} > <Outlet/> </Refine> ); } ``` routes/_index.tsx`

export default function Index() {
    const { isLoading, data } = useIsAuthenticated();

    const go = useGo();

    useEffect(() => {
        if (!isLoading && data?.authenticated) {
            go({ to: "/dashboard" ,type: "replace"});
        }
    }, [isLoading, data]);

    if (isLoading) {
        return <>Checking Login Status</> || null;
    }

    if (data?.authenticated) {
        return <>Redirecting</> || null;
    }

  return <Login />
}


Tried both use effect and just returning the go function.

Thanks for any help.
Was this page helpful?