I am new to React and I am getting this error. Can anyone help me on how to sort this. Thanks!
Full Warning Statement: Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
Sample code:
useEffect(() => {
fetchBlogs();
const subscription = DataStore.observe(Blog).subscribe(() => fetchBlogs());
return () =>{
subscription.unsubscribe();
};
}, [])
async function fetchBlogs() {
const blogData = await DataStore.query(Blog);
const sortedBlogs = blogData.sort((a,b) => b.createdAt > a.createdAt);
if (findTrueItem(sortedBlogs) !== undefined)
{
arrayMove(sortedBlogs,findPosition(sortedBlogs), 0);
}
setBlogs(sortedBlogs);
}