私はReact-reduxアプリケーションの開発にはとても新しいので、ページがロードされるとすぐに別のアクションをディスパッチする方法を理解しようとしています。以下は私のコンテナコードです。私はこの(https://github.com/jpsierens/webpack-react-redux)定型文を使用しています。 SETSTATE(...):私はレンダリング機能(IDK)の間にアクションを派遣していますので、おそらく既存の状態遷移中に更新できませんレンダリングコンテナの前にレスキューレスキューディスパッチアクションを実行する
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);
このコードは、私に警告を与えます。どのようにすれば、ページがロードされると自動的にactivateUser()関数をトリガーするように、指定されたコードを変換できますか?あなたのための
@Saad Anjumこの回答に記載されているライフサイクル機能を使用するには、 'React.Component'を拡張するために' ActivationPage'を変更する必要があります。 –
正しい方向に私を押してくれてありがとう@MichaelPeyperとYozi。それは今働いている。 –