React-admin: Missing resources in props for Menu

Created on 2 Nov 2017  路  8Comments  路  Source: marmelab/react-admin

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>)
  • Admin-on-rest version: ^1.3.2
  • React version: ^15.3.0

Thank you very much,
Jan

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!

All 8 comments

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.

https://marmelab.com/admin-on-rest/Admin.html#menu

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kikill95 picture kikill95  路  3Comments

phacks picture phacks  路  3Comments

9747749366 picture 9747749366  路  3Comments

fzaninotto picture fzaninotto  路  3Comments

aserrallerios picture aserrallerios  路  3Comments