[Answered ]-Array is not acting like an array and i don't know what to do

1👍

The issue is how you’re passing props here:

<Route element={<RequireAuth allowedRoles={['admin']}/>}>
   <Route path='admin' element={<Admin />} />
</Route>

const RequireAuth = (allowedRoles) => {  
    ...
}

The parameter allowedRoles being used in the RequireAuth functional component is really the props object. You’d need to destructure it if you want to use it as simply allowedRoles. Or you could pass it as props and manually call it where needed as props.allowedRoles.

So you could use either of these approaches:

<Route element={<RequireAuth allowedRoles={['admin']}/>}>
   <Route path='admin' element={<Admin />} />
</Route>

const RequireAuth = (props) => {  
    console.log(props.allowedRoles)
}

const RequireAuth = ({allowedRoles}) => {  
    console.log(allowedRoles)
}
👤Zack

Leave a comment