2つの異なるコンポーネントを入力すると、Facebookの有効期限と現在の日付をチェックする必要があります。 Dashboard
およびPages
。どちらも、このている:手動でページを更新する場合にのみcomponentWillUnmount()を使用してコンポーネントを終了するときにメソッドが実行されない
componentWillMount() {
const { linkedAccount, clearLinkedAccounts, getFacebookPages } = this.props
const now = moment().format('YYYY-MM-DD HH:mm:ss')
if (linkedAccount) {
if (now < linkedAccount.expiresIn) {
getFacebookPages()
} else {
clearLinkedAccounts()
}
}
}
componentWillUnmount() {
const { linkedAccount, clearLinkedAccounts } = this.props
const now = moment().format('YYYY-MM-DD HH:mm:ss')
if (linkedAccount && now > linkedAccount.expiresIn) {
clearLinkedAccounts()
}
}
しかし、clearLinkedAccounts()
はcomponentWillMount
を実行することによって、実行されますが、それを離れる前に、それはしていません。私は必要に応じて別のルートに入る前にそれを実行したい。
反応ルータコードも指定できますか? –