我在使用 useRecoilValue 时收到错误无效的挂钩调用。我用这个钩子错了吗?那么我该如何解决这个问题呢?
List.fn.js
import { Alert, AsyncStorage } from "react-native";
import { useRecoilValue } from "recoil";
import { listDataViewer } from "../State";
const ListFunction = (listName) => {
const listID = Date.parse(new Date());
const newListData = {
"ID": listID,
"Name": listName
};
const list = useRecoilValue(listDataViewer);
if (JSON.stringify(list) == "null"){
try {
AsyncStorage.setItem('list', JSON.stringify([list]));
} catch (error) {
console.log(error);
}
} else {
try {
AsyncStorage.setItem('list', JSON.stringify([newListData, ...list]));
} catch (error) {
console.log(error);
}
}
}
}