跳到主要内容

useRecoilState.js

实现


import { useState } from "react";

function useSetRecoilState(recoilState) {
const [, forceUpdate] = useState(0);
return (newValue) => {
recoilState.set(newValue);
forceUpdate((x) => x + 1);
};
}

function useRecoilState(recoilState) {
return [recoilState.get(), useSetRecoilState(recoilState)];
}

export default useRecoilState;