I am having an error from catch(error) console.log which is LOG [TypeError: Array.from requires an array-like object - not null or undefined]
Now i want to avoid null or undefined from my function before update it in useState. so how can i avoid null or undefined in here, my codes?
where should i use the function as i'm fetching data from API. anyone can help to use filter or any function to avoid null or undefined in my codes.
thanks for your trying in advance!
const [item, setItem] = useState();
async function fD() {
try {
const rA = await Promise.all(devices?.map((id) => {
const dT = fetch("https://jsonplaceholder.typicode.com/posts/1")
.then((response) => response.json())
.then((a) => {
return a;
})
.catch((error) => console.error(error));
return dT;
}));
setItem(rA);
}
catch (error) {
console.log(error);
}
}
In this case, null or undefined is coming from devices so need to make sure devices values doesn't have any null or undefine, that will be enough to solve this error as mention at the top. i have done the issues and figure it out, just think i should share the knowledge here.