What you were expecting:
Resources are passed in props to custom menu component
What happened instead:
Resources are undefined
Steps to reproduce:
const myMenu = ({ resources }) => { console.log(resources); return ''; };
return (
<Admin menu={myMeny} restClient={restClient('http://localhost:4000/api/fakeService')}>
<Resource name="endpoint" />
</Admin>)
Thank you very much,
Jan
You need to grab the resources from the state in your custom menu, as in https://github.com/marmelab/admin-on-rest/blob/master/src/mui/layout/Menu.js#L66
Reopening, I realize the doc is misleading on that point. It's indeed a documentation bug.
Thank you very much! That makes sense 馃挴
If I make my own menu, the compiler will throw an error.
Line 61: 'getResources' is not defined no-undef
I think it comes from the sample code in the documentation
const mapStateToProps = state => ({
resources: getResources(state),
})
But I don't know how to import the correct getResources from the 'admin-on-rest' module.
@alextsoi please ask the question on StackOverflow
Sorry, my mistake, I'll update the doc
Is getResources actually required? It seems to work OK with the mapStateToProps removed.
Otherwise, getResources will need to be publicized: it is a named export from /reducer/index.js, and only the default export from that file is available as createAppReducer in /index.js.
@fzaninotto we have just solved it as import { getResources } from "admin-on-rest/lib/reducer"; in our of our projects (thank you very much for admin-on-rest!), but to be honest I'm not so sure that's the right approach. If it is, happy to open a pr to fix the docs!
Most helpful comment
@fzaninotto we have just solved it as
import { getResources } from "admin-on-rest/lib/reducer";in our of our projects (thank you very much for admin-on-rest!), but to be honest I'm not so sure that's the right approach. If it is, happy to open a pr to fix the docs!