setup:
- @page1 loads list of items
- @page1 i have a link to route to @page2
- @page2 have dropdown list with items from @page1 via redux store/connect
works route> @page1 -> @page2
it works ok if the flow goes @page1 -> @page2 since it ensures items to be preloaded.
question how to be route -> @page2
but what is the best way to handle items when it directly goes to @page2 , should i somehow detect the route origin and load items @page2 again?
How are the items from page 1 being populated?
If I'm understanding your question correctly you shouldn't need to worry about how to handle the items since they are stored in your redux store.
When you do a
mapStateToProps
you can define what data from the store you want available to the page 2 component.There are many ways to do this, This example showcases how to achieve this using
Component
andActions
You can have your reducer setup like this
Your action can look like this
Now, Inside every component that relies on the data to be present, you can do something like
Note: I have used stateless component as an example here, and am using
setTimeout
to call theAction
if the data if not loaded.If you're using
React Class
you can placeprops.loadAppData();
within yourcomponentDidMount
method and it will work.