giao-hook
v1.0.4
Published
解决useEffect闭包陷阱问题,畅快拿到最新变更的state
Downloads
2
Maintainers
Readme
usage
import React, { useEffect, useState } from 'react'
import { useAsyncGetState } from 'giao-hook'
function App() {
const [count1, setCount1, getCount1] = useAsyncGetState(10)
const [count2, setCount2] = useState(0)
async function changeCount1() {
await setCount1(count1 + 1)
}
function changeCount2() {
setCount2(getCount1() * 10)
}
useEffect(() => {
changeCount1()
changeCount2()
}, [])
return (
<div>
<h2>count1: { count1 }</h2>
<h2>count2: { count2 }</h2>
</div>
);
}
export default App;