setState
には、UIの変更に応じて反映されない値を格納する必要はありません。
TouchableOpacityのクリックで設定したReact Classの中にthis.state.flag
の代わりにthis.flag
を直接持つことができます。したがって、this.flag
をレンダリングサイクルを含む非同期操作なしに設定することができます。それはちょうどあなたのコンポーネントが保持するフラグになります。
class SomeComponent extends React.Component{
constructor() {
super();
this.state = { ... }; // this does not need to store our flag
this.touchableInactive = false; // this is not state variable. hence sync
}
onButtonClick() {
if (!this.touchableInactive) {
this.touchableInactive = true;
// do stuff
}
}
// similarly reset this.touchableInactive to false somewhere else
}
:
以下の例を参照してください。