【发布时间】:2017-09-28 03:36:57
【问题描述】:
我对 React-redux 应用程序开发非常陌生,我正在尝试了解如何在页面加载后立即调度另一个操作。以下是我的容器代码。我正在使用这个 (https://github.com/jpsierens/webpack-react-redux) 样板。
let locationSearch;
const ActivationPage = ({activateUser}) => {
return (
<div className="container">
<h2>Activation Required</h2>
<p>An Activation Email was sent to your email address. Please check your inbox to find the activation link</p>
{ activateUser() }
</div>
);
};
ActivationPage.propTypes = {
activateUser: PropTypes.func
};
const mapStateToProps = (state) => {
return {
message: state.message,
currentUser: state.currentUser,
request: state.request
};
};
const mapDispatchToProps = (dispatch) => {
return {
activateUser: () => {
console.log(location);
if (location.search !== '') {
locationSearch = querystring.parse(location.search.replace('?', ''));
console.log(locationSearch);
if (locationSearch.hasOwnProperty('user_id') && locationSearch.hasOwnProperty('activation_code')) {
// change request state to pending to show loader
dispatch(actions.requestActions.requestPending());
}
}
}
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(ActivationPage);
这段代码给了我警告:setState(...): Cannot update during an existing state transition 可能是因为我在渲染函数 (IDK) 期间调度了一个动作。如何转换给定的代码以在页面加载后立即自动触发 activateUser() 函数。
【问题讨论】:
标签: javascript reactjs redux render setstate