:fire: Quick setup for performance orientated, offline-first React.js applications featuring Redux, hot-reloading, PostCSS, react-router, ServiceWorker, AppCache, FontFaceObserver and Mocha.
Hi, I'm new to this room but have been using react-boilerplate for a while now. I have a query about nested Redux states and would really appreciate it if someone can help me figure this out.
As per the redux docs, it's most advisable to keep the redux state separated as domains.
{
simpleDomainData1: {....},
simpleDomainData2: {....},
entities : {
entityType1 : {....},
entityType2 : {....}
},
ui : {
uiSection1 : {....},
uiSection2 : {....}
}
}
How do achieve this data structure in react-boilerplate
? I have been creating my Containers using the built-in generators, and keeping them all at the same level like so:
App
|__ Components
|__ Containers
|__ Container1
|__ Container2
|__ Container3
|__ Container4
:
:
My redux state is super normalized like so:
{
route: {
location: {
....
}
},
container1: {
data: {}
},
container2: {
data: {}
},
container3: {
data: {}
},
container4: {
data: {}
}
}
But I am now at a place where I need to nest Containers 2 and 3 within Container 1 (according to the business logic). How can I also mirror this structure on my redux store?
{
route: {
location: {
....
}
},
container1: {
data: {
container2: {
data: {...}
},
container3: {
data: {...}
},
}
},
container4: {
data: {}
}
}
How can we use injectReducer
to implement nested states? Or is there another approach that you all use? TIA!!
I have tried having all of the reducers for Container1
defined under /Container1
, thereby giving me control of the whole state, but that seems like an anti-pattern
I haven't yet tried nesting Containers
2 and 3 inside Container1
because I couldn't figure out how the injectReducer
util would work under those circumstances.
@agmm If you are in a component wrapper in withRouter
, you can just do something like this:
function Component(props) {
console.log(props.match, props.location);
}
.
.
export default withRouter(Component);
If your component is wrapper in the withRouter
HoC, match
, location
etc will be passed in as props
Anyone, in combination with semantic ui in the react-boilerplate (https://react.semantic-ui.com/usage), I executed the yarn add semantic-ui-react in the root directory of the react-boilerplate
There was an error:
Error /home/atom/FormalProject/react-boilerplate/node_modules/pngquant-bin: Command failed.
Exit code: 1
Command: node lib/install.js
Arguments:
Directory: /home/atom/FormalProject/react-boilerplate/node_modules/pngquant-bin
Output:
⚠ The /home/atom/FormalProject/react-boilerplate/node_modules/pngquant-bin/vendor/pngquant
binary doesn't seem to work correctly
Png pngquant pre-build test failed
i compiling from source
Png pngquant pre-build test passed successfully
✖ Error: pngquant failed to build, make sure that libpng-dev is installed