🚫 Warning: Functions are not valid as a React child. This may happen if you return a Component instead of from render. Or maybe you meant to call this function rather than return it.
function App() { return ( <div className="App"> <Routes> <Route path="/" element={Auth(LandingPage, null)} /> <Route path="/login" element={Auth(LoginPage, false)} /> <Route path="/register" element={Auth(RegisterPage, false)} /> */} </Routes> </div> ); }
React Router v6 부터 component={}
대신 element={}
를 사용해야 한다.
HOC 는 함수인데, element={}
에는 함수가 들어갈 수 없기 때문에 발생하는 오류이다. 오로지 컴포넌트만 넣을 수 있다.
import Auth from "../hoc/auth"
function App() {
const AuthLandingPage = Auth(LandingPage, null);
const AuthLoginPage = Auth(LoginPage, false);
const AuthRegisterPage = Auth(RegisterPage, false);
return (
<div className="App">
<Router>
<Routes>
<Route path="/" element={ <AuthLandingPage /> } />
<Route path="/login" element={ <AuthLoginPage /> }/>
<Route path="/register" element={ <AuthRegisterPage /> } />
</Routes>
</Router>
</div>
);
}
import Auth from "../hoc/auth"
const LandingPage = () => {
return (
{...}
);
};
export default Auth(LandingPage, null);