// Create RefconstisMounted=useRef(false);// Create Your Required Statesconst[posts,setPosts]=useState([]);const[isLoading,setIsLoading]=useState(false);const[error,setError]=useState('');// Create a function for fetching your dataconstfetchData=()=>{constfetchDb=db.collection('posts');fetchDb.get().then(response=>{constfetchedPosts=[];response.docs.forEach(post=>{constfetchedPost={id:post.id,...post.data(),};fetchedPosts.push(fetchedPost);});// check ref before updating state if(isMounted.current){setPosts(fetchedPosts);setIsLoading(false);}}).catch(error=>{// check ref before updating state isMounted.current&&setError(error);});};useEffect(()=>{isMounted.current=true;fetchData();// this is run when component unmountreturn()=>(isMounted.current=false);},[]);
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Checkout This Code