Looking for a React-Redux Boilerplate? If you are, you probably had no problem finding one. In fact, you probably found TONS of them ( ). From Andrew You also like Isomorphic Application: Best Practice Isomorphic learn by doing: Adding new page Since React and Redux was born, I was hooked on the paradise of in which we get and benefit of rendering on the server and you can still render the shared components after the page loads on the client and , which complements React’s composable view components by utilizing a unidirectional data flow. 1)React Isomorphic speed SEO 2) Ideas of Flux architecture After I pulled up thousands of isomorphic and flux boilerplate, I made a cup of tea to comfort myself, because non of them is short, the learning curve are distressingly steep, it means that there is not a shortcut and I need to start it from the ground up. This article is a note recorded the process how the boilerplate is broken down to understandable pieces, little by little. At the end, I concluded 5 big issue(functionalities or tags), they are the reason why creating so many isomorphic boilerplates: **Dev-Server &Build Bundle:**Setup development and production environment, mainly to solve the problem of etc. Popular tools: webpack, gulp, nodenpm, browserify and grunt. hot-reload, auto-watch, bundle build *React-Redux Components and Data flow **Routing**To decide what routing hierarchy is used, we should ask ourself few questions: Is it a single page website? Dose the API server support cross-origin? Is wrapping inside express server better than client side? **Share Reducer/Action Creator**It is related to Routing Test Here, we are going to talk about the 2nd point, it is the only one common part amount the thousand of boilerplate, and the rest of four are changed variedly by different preference of developers. , and are the core of isomorphic and flux architecture, that is the reason why every boilerplate is using the modules of ‘react’, ‘redux’ and ‘react-redux’. Server-side rendering shared components Redux module Clone the from Github, a hellowWorld example which base on React-Redux, and we are going to break it down to pieces to understand how each file works: repository React Redux server rendering structure Above is the structure of how the whole app works, the app bases on Express web framework, which serves only one route, with function to put index.html into the browser. Inside the scoop of the structure, what we are interested is the blue box, the interaction between react component, redux, root component, store and reducer. res.sendFile React Redux Structure of data, store, props, state and component This is an example followed by , the Facebook team proposes couple of advise and design principle to the hierarchy of components, for example: separated container and presentational components, use rather than etc. official documentation connect() store.subscribe() , as the entry file and a high level root component, which gathers all the sub-component as the subtree of the Virtual DOM, also it is the only file entangled with many independent modules. Apart from it, different file requires independent modules, which makes clean code and work independently. index.js Up to here, I really feel that Facebook have done a lot to us, developers. Different file response for independent work Below are the functions which play important roles in react-redux components: <Provider> It make the available to components in the application without passing it explicitly. You only need to use it once when you render the root component: magically store all container import { Provider } from 'react-redux'let store = createStore(todoApp) render( <App /> document.getElementById('root')) <Provider store={store}> </Provider>, connect( … ) allows the component to use the top-level store without having to pass the store down as a prop through its parent components ( ). Connecting a React component to Redux from Inject store to Root Component To start connecting components, we have to wrap our root component in and pass it the variable: Provider, store import helloReducer from './reducers'import { Provider } from 'react-redux'import { createStore } from 'redux'let store = createStore(helloReducer) render( <App /> document.getElementById('root')) <Provider store={store}> </Provider>, 2. Connecting store to presentational components The describe many ways to use c_onnect_. To my purpose, only and are needed to fulfill the functionality. React Redux docs mapStateToProps mapDispatchToProps — mapping state to props will provide the component from the Hello this.props. message Redux store — mapping dispatch functions for actions to props will make available as functions in component . HELLO_WORLD this.props. onClick Hello const = (state, ownProps) => {return { : state.helloWorld.message}} mapStateToProps message const = (dispatch, ownProps) => {return {onClick: () => {dispatch({ type: HELLO_WORLD })}}} mapDispatchToProps const HelloWorld = connect( , )(Hello) mapStateToProps mapDispatchToProps Must know NPM Module Below are some NPM modules which many people may not know: react-redux Redux&React bindings are not included in Redux by default. You need to install npm package explicitly. This assumes that you’re using npm package manager with a module bundler like or to consume CommonJS modules. react-redux Webpack Browserify webpack-dev-middleware It’s a simple wrapper middleware for webpack. It serves the files emitted from webpack over a connect server. This should be used for . development only ( more ) * No files are written to disk, it handle the files in memory webpack-hot-server-middleware It is designed to be used in conjunction with to Webpack bundles on the server ( ). [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware/), hot update more Remark Below are some concept and terminology: HMR stands for ‘ ’, sometimes called ‘ ’. It’s a Webpack feature that updates your JavaScript in-place without a browser refresh ( ). Hot Module Replacement hot module swapping more combineReducers( ... ) It turns an object whose values are different reducing functions into a single reducing function you can pass to . createStore createStore (reducer, [preloadedState], [enhancer]) To create a Redux that holds the complete state tree of your app. store the which will be passed in createStore(reducer, [initialState], [enhancer]) <Provider>: import { createStore, combineReducers } from 'redux' function (state = [], action) {switch (action.type) {case 'ADD_TODO':return state.concat([ action.text ])default:return state}} todos function (state = [], action) {switch (action.type) {case 'PRE_ADD_TODO':return state.concat([ 'pre_'+action.text ])default:return state}} prefixTodos const = combineReducers({ , }) mixReducers todos prefixTodos let store = createStore( , [ 'Use Redux' ]) mixReducers subscribe( … ) VS connect(…) They are doing the same things in Redux, but React officially announces that advise you to use , for the reasons that React Redux makes many performance optimizations that are hard to do by hand. NOT store.subscribe() , generally we generate with to connect them to the store. connect() container components connect() Redux Container Components VS Presentational Components I also heard and , and and , and Components could be divided into two categories , Fat Skinny Smart Dumb, Stateful Pure Screens Components ( from ): : Provide the data and behavior to presentational or other container components. Container Components : 1) Have no dependencies on the rest of the app, 2) Are concerned with Presentational Components how things look. Like this story? It is helpful to others? It helps me know if you’d like to see write more about his topic and helps people see the story, . when tap the heart below Reference: https://www.npmjs.com/package/redux http://redux.js.org/docs/introduction/Examples.html https://medium.com/@firasd/quick-start-tutorial-using-redux-in-react-apps-89b142d6c5c1 http://andrewhfarmer.com/starter-project/ https://www.codementor.io/reactjs/tutorial/redux-server-rendering-react-router-universal-web-app https://github.com/WilberTian/StepByStep-Redux/blob/master/06.react-redux.md