React native 按时间限制模式的最佳实践

React native 按时间限制模式的最佳实践,react-native,react-redux,redux-thunk,react-native-elements,React Native,React Redux,Redux Thunk,React Native Elements,我正在React Native中构建一个简单的测验应用程序。当用户得到正确答案时,我想显示一个弹出模式(React Native Elements),上面写着“恭喜”。我的工作如下: <Overlay isVisible={{this.props.showModal}}> <Text>Congratz</Text> </Overlay> 恭喜 其中,showModal通过我的Redux和Redux Thunk操作中的分派进行设置。然而,我

我正在React Native中构建一个简单的测验应用程序。当用户得到正确答案时,我想显示一个弹出模式(React Native Elements),上面写着“恭喜”。我的工作如下:

<Overlay isVisible={{this.props.showModal}}>
  <Text>Congratz</Text>
</Overlay>

恭喜
其中,showModal通过我的Redux和Redux Thunk操作中的分派进行设置。然而,我想限制这只显示2秒钟,然后消失。实现这一目标的最佳实践是什么

目前我的thunk操作是:

export const showModal = () => {
  return (dispatch, getState) => {
    dispatch({ type: "SHOW_MODAL" });
    var start = new Date().getTime();
    var end = start;
    while (end < start + 2000) {
      end = new Date().getTime();
    }
    dispatch({ type: "HIDE_MODAL" });
  };
};
export const showmodel=()=>{
返回(调度,获取状态)=>{
分派({type:“SHOW_MODAL”});
var start=new Date().getTime();
var结束=开始;
而(结束<开始+2000){
end=新日期().getTime();
}
分派({type:“HIDE_MODAL”});
};
};

但这会将系统锁定2秒钟?

我将使用简单的
设置超时
功能在调度
后调度
隐藏\u模式

dispatch({ type: "SHOW_MODAL" });
setTimeout(() => dispatch({ type: "HIDE_MODAL" }), 2000);