In React js, What I want to do is: declare an array of objects (routes) and export. For conditional declaration of array of objects, I want to use an state variable (which returns whether user logged in or not).
Aim:
- user logged in, show
Put Rating
option - user not logged in, dont show
Put Rating
option.
The file of array of objects which I have to export for mapping
import {AppState} from '../AppContext';
function IsLoggedIn(){
const {user} = AppState();
return user===null;
}
const routes=[
{
title:"home page",
show:true,
},
{
title:"put rating",
show: IsLoggedIn(),
}
];
export default routes;
It returns error like hooks can only be used inside body of functions.