基本上以下两段代码有什么区别?我们可以说 useReactiveVar 是一种具有重新渲染功能的 useRef 吗?
- useState(这会记录“ iAmAwesome ”吗?)
const [awesomeVar, setAwesomeVar] = useState("iAmAwesome");
setTimeout(() => console.log(awesomeVar), 1000);
setAwesomeVar("youAreAwesome");
- useReactiveVar(这会记录“ iAmAwesome youAreAwesome ”吗?)
const reactiveVar = makeVar("iAmAwesome");
// ...
const awesomeVar = useReactiveVar(reactiveVar);
setTimeout(() => console.log(awesomeVar, useReactiveVar()), 1000);
useReactiveVar("youAreAwesome");