I got an error Invalid hook call when I am using useRecoilValue. Am I wrong to use this hooks? then how can I solve this problem?
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);
}
}
}
}