Closed ric-kin closed 6 years ago
Hi, and thanks for your question. As explained in the react-admin contributing guide, the right place to ask a "How To" question, get usage advice, or troubleshoot your own code, is StackOverFlow.
This makes your question easy to find by the core team, and the developer community. Unlike Github, StackOverFlow has great SEO, gamification, voting, and reputation. That's why we chose it, and decided to keep GitHub issues only for bugs and feature requests.
So I'm closing this issue, and inviting you to ask your question at:
http://stackoverflow.com/questions/tagged/react-admin
And once you get a response, please continue to hang out on the react-admin channel in StackOverflow. That way, you can help newcomers and share your expertise!
Apologies but blindly redirecting someone to SO without even having a look at the problem is strong ignorance.
This is problem of the documentation, definitely not something which should be handled on SO side.
So here's the solution:
You need to manually register resource because you don't use Resource
component which does that.
So right after you create the store call registerResource
action manually.
import * as reactAdmin from "ra-core";
...
...
const store = createStore....
store.dispatch(reactAdmin.registerResource({
name: "myStuff",
hasList: true,
hasEdit: false,
hasShow: false,
hasCreate: false
}));
For 90% of people this is a showstopper when they want to integrate react-admin. Because finding this out will require some source code digging.
Apologies but we might simply have missed this while actively working on this open-source project. Putting all this negativity in a comment instead of simply opening a pull request fixing the documentation is a strong waste of time. I'll gladly accept a pull request though
Thank you very much for your help. I was about to ditch using react-admin since I could not get it running properly. Your apology is welcome, I would suggest to keep the github issue public so other users can benefit from your response.
On jue, jul 19, 2018 at 5:52 , Tomáš Weiss notifications@github.com wrote:
Apologies but blindly redirecting someone to SO without even having a look at the problem is strong ignorance.
This is problem of the documentation, definitely not something which should be handled on SO side.
So here's the solution:
You need to manually register resource because you don't use Resource component which does that.
So right after you create the store call registerResource action manually.
import * as reactAdmin from "ra-core"; ... ... const store = createStore....
store.dispatch(reactAdmin.registerResource({ name: "myStuff", hasList: true, hasEdit: false, hasShow: false, hasCreate: false })); For 90% of people this is a showstopper when they want to integrate react-admin. Because finding this out will require some source code digging.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
@djhi I never meant to offend you, seriously. I really appreciate all the effort that you've put into this project. However, open sourcing this kind of library is a huge commitment. Especially for the project like this which is likely a foundation block. So yeah, sorry for being negative.
I am just a bit tired of fixing a lot of issues caused by the decision to use react-admin as foundation for our app. I don't simply feel like it's stable enough. Which is fine - I do understand it's non-trivial effort to build something like react-admin.
However, I would really appreciate to slow down and focus on improving quality - meaning tickets like these should have highest priority. Thank you for your time anyway.
blindly redirecting someone to SO without even having a look at the problem
You don't know that.
open sourcing this kind of library is a huge commitment
Using open source software implies an invitation to improve it yourself.
I would really appreciate to slow down and focus on improving quality
They would really appreciate you contributing.
I am just a bit tired of fixing a lot of issues
The more I use react-admin, the more I like it.
@tomkis No problem. Can you be more specific about what you think isnt' stable enough? We are currently focusing on fixing bugs and adding some features without breaking changes.
I would really appreciate more detailed feedbacks. By the way, we use react-admin on almost all our client projects and many have really huge admins. Some of them push react-admin to its limits too ;)
Reopening the issue and marking it as a documentation problem
@ric-kin Would you mind explaining why you need to use react-admin
like this ? Is it because of the redux store?
@djhi I want to use react-admin as part of a larger application where the admin panel is a subcomponent of an existing redux app. And yes, the main reason for not using the <Admin>
and <Resource>
approach is that <Admin>
creates its own store. I considered to add a route that redirects to <Admin>
but it would only work as long as it is defined outside of the larger app's <Provider>
and its respective <Connected Router>
.
@ric-kin Thanks! I'm investigating a way to make this use case easier :)
@djhi I kinda had the same use case.
Basically provide our own store. How about it would be possible to pass store down through the props optionally?
IMO this would be most comfortable for the users.
Also another problem with this approach is that users that want / have to use different router than react-router (I use router5) are basically screwed. Application heavily relies on the presence of the router. React-admin could definitely leverage from more abstraction on this front.
Unfortunately, I do not have time to do any rewrite of our app so I can't share concrete obstacles. But once I free myself up a bit, I will definitely share my two cents.
Basically provide our own store. How about it would be possible to pass store down through the props optionally?
It first requires that we rewrite all our state reading operations using selectors (which is a good thing anyway). Then we could follow the redux-form approach. This would be great but will take some time to implement so don't expect it soon
Also another problem with this approach is that users that want / have to use different router than react-router (I use router5) are basically screwed. Application heavily relies on the presence of the router. React-admin could definitely leverage from more abstraction on this front.
Not screwed but they'll have to rewrite significant parts of the library. The good news is those parts should not be too hard to implement: (The Resource
component, the mapDispatchToProps
of some components, mostly Controllers from ra-core
and the auth
and redirection
side effects.
I'll think about how we could make this easier though
I'm -1 about making the router configurable. This is one of the fundamental building blocks for react-admin (together with Redux, saga, and redux-form).
What's wrong with react-router?
@djhi Shouldn't we just add <Resource context="registration" ... />
lines in the Custom app documentation snippet?
or, since we explain how to create a custom store in CustomApp, I guess we can even accept an external store and skip the creation of our own if it's provided.
I'm -1 about making the router configurable. This is one of the fundamental building blocks for react-admin (together with Redux, saga, and redux-form).
What if someone has a running application that they either want gradually rewrite to RA or just add it on top of that? They would either be forced to use react-router (which may not always be an option) or they may need to use two collocated routers - which is really impractical.
Not screwed but they'll have to rewrite significant parts of the library. The good news is those parts should not be too hard to implement: (The Resource component, the mapDispatchToProps of some components, mostly Controllers from ra-core and the auth and redirection side effects.
or, since we explain how to create a custom store in CustomApp, I guess we can even accept an external store and skip the creation of our own if it's provided.
Not that simple but yes, I'll try to tackle this asap
Fixed by #2141
Is there a demo or example application to show the integration with custom react app please?
Does anyone have an example to show the integration with custom react app?
@btoro What's wrong with https://marmelab.com/react-admin/CustomApp.html?
What you were expecting: Include react-admin into existing project. Followed instructions on: https://marmelab.com/react-admin/CustomApp.html
What happened instead: When loading a simple List component, output is: TypeError: resourceState is undefined mapStateToProps node_modules/ra-core/lib/controller/ListController.js:413
410 | 411 | return { 412 | query: getQuery(props),
Other information: I passed the "admin", "form" and "i18n" props to the List component. However, admin prop contains no resources. In other words, how can I bootstrap resources to my store's 'admin' state manually?
Environment