选择器在组件渲染之前执行
Selectors are executed before component is rendered
我的选择器在渲染它们映射的组件之前执行。为什么会这样?例如在下面的代码中,messages
选择器在 Component
呈现之前执行。谢谢!
import React from 'react';
import {connect} from 'react-redux';
import * as selectors from './selectors';
const Component = ({message}) => (
<div>
{message}
</div>
);
const mapStateToProps = (state, props) => ({
message: selectors.message(state, props),
});
export default connect(mapStateToProps)(Component);
在React-Redux v5中,实现mapState
的内部选择器是initialized in the wrapper component constructor, and is called right away as part of that process.
在 React-Redux v6 中,内部选择器是 created in the wrapper component constructor, but called during the render process。
我的选择器在渲染它们映射的组件之前执行。为什么会这样?例如在下面的代码中,messages
选择器在 Component
呈现之前执行。谢谢!
import React from 'react';
import {connect} from 'react-redux';
import * as selectors from './selectors';
const Component = ({message}) => (
<div>
{message}
</div>
);
const mapStateToProps = (state, props) => ({
message: selectors.message(state, props),
});
export default connect(mapStateToProps)(Component);
在React-Redux v5中,实现mapState
的内部选择器是initialized in the wrapper component constructor, and is called right away as part of that process.
在 React-Redux v6 中,内部选择器是 created in the wrapper component constructor, but called during the render process。