Giter VIP home page Giter VIP logo

react-redux-boilerplate's Introduction

react-redux-boilerplate

  • It is React-Redux as infrastructure boilerplate, with this developers just focus on developing component, action creator and reducer, without spending time in router, dev/pro build enviroement, wiring up file and express as HTTP server.

Read more

Install

$ git clone https://github.com/wahengchang/react-redux-boilerplate
$ npm install

Run (Develop Mode)

It is runnign in Development mode, enable HMR

$ npm run dev
open http://localhost:3000/

Run (Production Mode)

  • Compiling react/redux script to browser use lib, with webpack default optimized config.
  • Disable unnecessary funtionality which helps to debug in development mode
$ npm run build
$ npm run start

Test

More detail: about test of action creater, component, container and reducer

$ npm run test


Test Suites: 4 passed, 4 total
Tests:       6 passed, 6 total
Snapshots:   0 total
Time:        1.824s, estimated 2s

or watch mode

$ ./node_modules/jest/bin/jest.js --watchAll #runs all tests

Server Rendering Structure

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 res.sendFile 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.

Shared Components

react-redux-universial-container-compont

React-Redux Structure

react-helloworld-component-5-20 index.js , 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.

Must Know

<Provider>

It magically make the store available to all container components in the application without passing it explicitly. You only need to use it once when you render the root component:

import { Provider } from 'react-redux'
let store = createStore(todoApp)

render(
  <Provider store={store}>
    <App />
  </Provider>,
  document.getElementById('root')
)

connect( ... )

Connecting a React component to Redux allows the component to use the top-level store without having to pass the store down as a prop through its parent components

combineReducers( ... )

It turns an object whose values are different reducing functions into a single reducing function you can pass to createStore.

createStore( ... )

To create a store the createStore(reducer, [initialState], [enhancer]) which will be passed in :

Container Components VS Presentational Components

Components could be divided into two categories, I also heard Fat and Skinny, Smart and Dumb, Stateful and Pure, Screens and Components:

  1. Container Components: Provide the data and behavior to presentational or other container components.
  2. Presentational Components: 1) Have no dependencies on the rest of the app, 2) Are concerned with how things look.

Credit

https://github.com/vaibhavmule/react-redux-helloworld

react-redux-boilerplate's People

Contributors

wahengchang avatar

Stargazers

Dumpling avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.