在具有异步操作的react-redux应用程序中使用`reselect`

时间:2016-09-01 19:27:21

标签: asynchronous reactjs redux reselect

如果我正在使用异步redux库以及重新选择,那么当状态对象被选中时,是否存在用于在mapStateToProps中执行选择的确定模式"取决于异步操作的完成情况?

我使用以下解决方案,但似乎不够优雅......

const mapStateToProps = (state) => {
    if (state.roles.list.length) {
        return {
            role: selectRole(state),
            permissions: selectPermissions(state)
        }
    } else {
        return {}
    }
}

class MyComponent extends React.Component {
    componentDidMount() {
        this.props.dispatch(getAllRolesAndPermissions());
    }
    ...
}

connect(mapStateToProps)(MyComponent)

我如何执行"选择"使用reselect库的状态依赖于异步操作来填充状态?

0 个答案:

没有答案