既存の状態遷移時に更新できません:警告:SETSTATE(...)は:私は次のエラーを取得しています
Warning: setState(...): Cannot update during an existing state transition (such as within `render` or another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to `componentWillMount`.
マイコンポーネント:
import React from 'react';
import { Redirect } from 'react-router'
import Notifications from 'react-notification-system-redux';
constructor(props) {
super(props);
this.state = {
invite_token: this.props.match.params.token,
FormSubmitSucceeded: false,
inviteRequestSubmitSucceeded: false
};
}
....
inviteAlreadyUsed() {
const notificationOpts = {
message: 'Invitation already used!',
};
this.props.createNotificationSuccess(notificationOpts);
}
render() {
const { invite } = this.props;
if (invite && invite.status === "completed") {
this.inviteAlreadyUsed();
return <Redirect to={{ pathname: '/' }}/>;
}
...
回避する方法上の任意の提案この警告?これはあなたがリダイレクトを扱う方法ではありませんか?
あなたのコンストラクタは見えますか? –
@HanaAlaydrusが追加されました – AnApprentice
あなたの例では、状態を設定している場所が表示されません。警告は、コンストラクタまたはレンダリングメソッドで呼び出すことを警告します。これが起こっている場所を見つけて、 '' setState''をリファクタリングする必要があります。 – archae0pteryx