0
私はコンポーネントをラップするためにホークを使用しています。このホックは、アンマウントされたときにアクションをディスパッチします。これを行うには、 'resetState'メソッドを呼び出します。しかし、ラップされたコンポーネントの別の場所で同じものをresetState()
と呼びたい場合はどうすればいいでしょうか。 this.resetState
は(論理的に)うまくいかないので、私は関数をラッパーの小道具として渡すことしか想像できません。反応の中でラッパーのメソッドを呼び出す方法
const resetAtUnmount = function (type) {
// return the function to be called by redux 'connect'
return function decorate(WrappedComponent) {
// return the final class
return class extends React.Component {
resetState() {
store.dispatch({ type });
}
componentWillUnmount() {
this.resetState();
}
render() {
return <WrappedComponent {...this.props} />;
}
};
};
};
エクスポートのデフォルトresetAtUnmount;
アクションを使用してresetState – WitVault