美文网首页
react-native 同步useState

react-native 同步useState

作者: Biao_349d | 来源:发表于2024-01-08 09:48 被阅读0次

    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) }
    

    相关文章

      网友评论

          本文标题:react-native 同步useState

          本文链接:https://www.haomeiwen.com/subject/revnndtx.html