getDerivedStateFromProps
次のようにコンポーネントで使用しようとしています:
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
location: '',
};
}
static getDerivedStateFromProps(nextProps, prevState) {
return {
location: nextProps.location.pathname,
};
}
render() {....}
}
const EnhancedComponent = withRouter(MyComponent);
export default EnhancedComponent;
そして警告を受けるStateless functional components do not support getDerivedStateFromProps.
withRouter
ステートレスな機能コンポーネントを返していますか? この警告の意味がよくわかりません。ここに光を当てたい!
ちなみに派生状態はちゃんと更新されています。