Why useEffect hook is calling multiple times in React?

I am creating a web app in React and when I try to call dispatch inside 'useEffect' hook it is calling multiple times. Can you please help me to find out the issue. Below is the code that I am using

useEffect(() => {
    dispatch(fetchPosts());
});
1 Answers

You can use below code to fix this

useEffect(() => {
   dispatch(fetchSnippets());
}, []);
Never leave your website again in search of code snippets by installing our chrome extension.