We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react 入口还是在这里: ReactDOM.render(<Provider store={store}><App/></Provider>, document.getElementById('root')); 由babel compiler 将<Provider store={store}><App/></Provider>转译成: ReactDOM.render(createReactElement(Provider, {store: store}, createReactElement(App))) 执行顺序:
ReactDOM.render(<Provider store={store}><App/></Provider>, document.getElementById('root'));
<Provider store={store}><App/></Provider>
ReactDOM.render(createReactElement(Provider, {store: store}, createReactElement(App)))
创建App element的具体过程请看这篇。
我们重点来看看Provider的创建过程:
var Provider = /*#__PURE__*/ function (_Component) { _inheritsLoose(Provider, _Component); function Provider(props) { var _this; _this = _Component.call(this, props) || this; var store = props.store; _this.state = { storeState: store.getState(), store: store }; return _this; } var _proto = Provider.prototype; _proto.componentDidMount = function componentDidMount() { this._isMounted = true; this.subscribe(); }; _proto.componentWillUnmount = function componentWillUnmount() { if (this.unsubscribe) this.unsubscribe(); this._isMounted = false; }; _proto.componentDidUpdate = function componentDidUpdate(prevProps) { if (this.props.store !== prevProps.store) { if (this.unsubscribe) this.unsubscribe(); this.subscribe(); } }; _proto.subscribe = function subscribe() { var _this2 = this; var store = this.props.store; this.unsubscribe = store.subscribe(function () { var newStoreState = store.getState(); if (!_this2._isMounted) { return; } _this2.setState(function (providerState) { // If the value is the same, skip the unnecessary state update. if (providerState.storeState === newStoreState) { return null; } return { storeState: newStoreState }; }); }); // Actions might have been dispatched between render and mount - handle those var postMountStoreState = store.getState(); if (postMountStoreState !== this.state.storeState) { this.setState({ storeState: postMountStoreState }); } }; _proto.render = function render() { var Context = this.props.context || ReactReduxContext; return React.createElement(Context.Provider, { value: this.state }, this.props.children); }; return Provider; }(Component); Provider.propTypes = { store: PropTypes.shape({ subscribe: PropTypes.func.isRequired, dispatch: PropTypes.func.isRequired, getState: PropTypes.func.isRequired }), context: PropTypes.object, children: PropTypes.any }; export default Provider;
未完待续。。。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
react 入口还是在这里:
ReactDOM.render(<Provider store={store}><App/></Provider>, document.getElementById('root'));
由babel compiler 将
<Provider store={store}><App/></Provider>
转译成:ReactDOM.render(createReactElement(Provider, {store: store}, createReactElement(App)))
执行顺序:
创建App element的具体过程请看这篇。
我们重点来看看Provider的创建过程:
未完待续。。。
The text was updated successfully, but these errors were encountered: