I have working on a Social media Application and getting stuck with this.
Inside src > component > PostList
I have used useEffect
with empty dependency array but whenever I went createPost inside SideBar and come Back useEffect again render that causes me not able to add any extra post .
https://github.com/santukumar01/learning-react/tree/main/Social%20Media%20App%20-%20version-%202
How to resolve this and why every useEffect
is runnung .
2
Answers
Your useEffect is re-running because the components are remounting every time
selectedTab
in your Sidebar.jsx changes:To fix this I recommend moving your data fetch into a more stable place like context or an external state management solution like zustand, then passing the data as props to PostList.