Wednesday, March 8, 2017

Some notes on redux/ES6/react

-Actions must have type property.The rest of object's properties are arbitrary

-Be careful with exporting classes. They need to be instanced after import.

-Make sure your next state resets the props on which components depend, as componentWillReceivedProps() won't be called unless the prop it's bound to hadn't  been actually changed!

combineStores changes the structure of state object.
Each reducer inside of the combined reducer object gets a property.

For example:

combineReducers{

    appReducer,
    selectActivityReducer
}

will result in a state object like this:

{
    appReducer:{
      //state variables set in appReducer
   }
   ,

   selectActivityReducer:{
      ///state variables set in selectActivityReducer
   }

}




For redux, and react-redux, documentation is incomplete. It's a good idea to look at blogs of some of the key code contributors, or git repos directly.


UI state should be separated from data state, if possible.

UI componentns should be stateless, functional and separated in a special folder.

Container components should be connected to redux store and should receive updates using props. They should call UI components, and set props for them.

Another good idea is to look for blog posts of people who already had problems with Redux/React and who can share some useful concepts and tips. For example, here:
https://medium.com/@docodemore/why-you-don-t-need-react-redux-31b5aebb38a9#.g6b0xmvqt




-Reducers should be pure

Actions are triggered from container components.


If using webpack 2, every loader needs to have suffix -loader when used. For example:

{
  test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
  loader: 'url-loader?limit=10000&mimetype=image/svg+xml'
}

instead of

{
  test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
  loader: 'url?limit=10000&mimetype=image/svg+xml'
}


No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...