Problem aIn ES6, you often see constructor(props) and super(props) together, so why is this?

Meaning:

  1. In ES6, the reason for calling super(props) is that this can only be used if super was called from constructor; The constructor(props) parameter is passed with respect to ES5 inheritance (by passing the parameter)
  2. The purpose of super(props) is to be able to use super.props

If you don’t need this in a subclass, constructor can dispense with super(props). This also doesn’t affect render() using this, which comes automatically with React

Question 2And the compose of story

Meaning:

Source: github.com/reduxjs/red…

funcs.reduce((a, b) => (… args) => a(b(… Args))).

This is to wrap functions in onion rolls and call them layer by layer, with the return value of the previous function as the argument of the next function. As a graph:

For detailed explanation:

The compose of story

Compose source analysis in REdux

Reducer reducer reducer reducer reducer reducer reducer reducer

Let’s start with the learning process:

In the book the way to advance React, combineReducers mentions two equivalents. As follows:

Writing a:

import { combineReducers } from 'redux';

const chatReducer = combineReducers({
  todos,
  visibilityFilter
})
Copy the code
const chatReducer = (state = {} action) = > {
  return {
    todos: todos(state.todos, action),
    visibilityFilter: visibilityFilter(state.visibilityFilter, action)
  }
};
Copy the code

These two ways are equivalent.

Method 2:

const reducer = combineReducers({
  a: doSomethingWithA,
  b: processB,
  c: c
})

/ / is equivalent to
function reducer(state = {}, action) {
  return {
    a: doSomethingWithA(state.a, action),
    b: processB(state.b, action),
    c: c(state.c, action)
  }
}
Copy the code

According to the book, the properties in the state passed by combineReducers to each Reducer depend on the key value of its parameter object.

There was some disagreement in this area, so make a note of it.

Meaning:The queryV. Split the Reducer”The senior pointed out

The first equivalent writing method has a premise that the attribute name of State must be the same as that of Reducer. If the names are different, use the second equivalent.

 

References:

React components need to be super(props)

Redux Tutorial part 1: Basic Usage