3 ms·
My key to success with react-router was to use context and redux to get props to the routed components. Sub-components from there can accept props directly. Af
by fraserharris 10y ago
My key to success with react-router was to use context and redux to get props to the routed components. Sub-components from there can accept props directly. After a while it feels natural - any necessary information is stored in the store.
- BigJono 10y agoThis is an anti-pattern unless you actually have shared state between pages. Otherwise it's functionally no different to just having local state on each page and all you have is lots of unnecessary boilerplate. This is way more common than I realised before I started working in teams. Each page does it's own API calls to the server (either directly, or more commonly through some sort of horrible misuse of redux-thunk), stores the data in it's own little section of the redux store, and then receives the exact same data back as props :/
- fraserharris 10y agoIn general, you only need react-router if you have multiple pages with some kind of shared state (ie: a dashboard). I do know exactly what you are talking about. We do have some single pages that implement the boiler plate just so that they are consistent with the others.