this.stateに値が設定できないーー。 undefinedなものに入れようとしていた
class IndexSidebar extends React.Component { constructor(props){ super(props); console.log("IndexSidebar context"); console.log(this.props.context.userStore.getUserData()); this.state.userStore = this.props.context.userStore; // NG this.userStore = this.props.context.userStore; // OK this.state = { userStore: this.props.context.userStore}; // OK }
Uncaught TypeError: Cannot set property 'userStore' of undefined
となっていて発狂しそうになっていたら
まだ、constructorの中ではstateが初期化されていないということか。
これ分かるのに、どれだけ時間がかかっているんだろう。自己嫌悪に。。