react-redux connectAdvanced.selectDerivedProps()更新问题

时间:2019-02-08 15:14:34

标签: react-redux

react-redux 6.0

Q1:我想知道lastState === state中的什么时候成立,如果状态不变,我认为它不会在Provider.js中调用setState

Q2:除第一次外,在store !== lastStore中会为真

Provider.js
      this.setState(providerState => {
        // If the value is the same, skip the unnecessary state update.
        if (providerState.storeState === newStoreState) {
          return null
        }

        return { storeState: newStoreState }
      })
    })
connectAdvanced.js
      return function selectDerivedProps(
        state,
        props,
        store,
        selectorFactoryOptions
      ) {
        if (pure && lastProps === props && lastState === state) {
          return lastDerivedProps
        }

        if (
          store !== lastStore ||
          lastSelectorFactoryOptions !== selectorFactoryOptions
        ) {
          lastStore = store
          ...
        }

0 个答案:

没有答案