hooks/setAsyncState.ts
function setAsyncState(fn: Function, value: any, callback?: Function) {
return new Promise((resolve, reject) => {
fn(() => value)
resolve(value)
return value
}).then(res => {
callback && callback()
return res
})
}
export default setAsyncState
const [list, setList] = useStae([])
setAsyncState(setList,[1,2], () => {
onRefresh()
})
const onRefresh = () => { console.log(list) }
网友评论