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
setState
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)); }
( component: Component
, state: ((prevState: Readonly, props: Readonly
) => (Pick | S | null)) | Pick | S | null ) { return new Promise(resolve => component.setState(state, resolve)); }