Using async setState

前端 未结 5 2138
清歌不尽
清歌不尽 2020-11-28 04:42

I have function which dispatched an action. I would like to display a loader before and after the action. I know that react composing the object passed to setState

5条回答
  •  情书的邮戳
    2020-11-28 05:22

    Here's a typescript implementation of an "async-await" setState:

    async function setStateAsync(
      component: Component,
      state:
        ((prevState: Readonly, props: Readonly

    ) => (Pick | S | null)) | Pick | S | null ) { return new Promise(resolve => component.setState(state, resolve)); }

提交回复
热议问题