I currently use react-router-dom to separate routing for authenticated/non-authenticated people. But Element has an error for missing the properties.
How can withoutAuth() work for authentication routes?
Type '() => Element' is missing the following properties from type 'ReactElement<any, string | JSXElementConstructor>': type, props, key
function App() {
return (
<BrowserRouter>
<AuthProvider>
<Routes>
<Route path="/dashboard" element={<Dashboard />} />
<Route path="/" element={withoutAuth(<Signup />)} />
</Routes>
</AuthProvider>
</BrowserRouter>
);
}
const withoutAuth = (Element: ElementType) =>
function WithoutAuth() {
const { currentFBUser } = useAuthContext()
if (currentFBUser) {
return <Navigate to="/dashboard" />
}
return <Element />
}