语法
代替 useMemo
一、缓存实例,确保实例只创建一次
import { useCreation, useUpdate } from "ahooks";
class Person {
constructor() {
console.log("Person");
this.num = Math.random();
}
}
function App() {
const person = useCreation(() => new Person(), []);
const update = useUpdate();
return (
<div>
<h3>useUpdate</h3>
{person.num}
<button onClick={update}>刷新</button>
</div>
);
}
export default App;