I am trying to load data to my App.js
file in react from the backend.
I have used redux to build the whole data fetching and storing pipeline from backend to frontend.
Here is the code :
function App() {
const dispatch = useDispatch();
useEffect(() => {
dispatch(getPosts());
}, [dispatch]);
const posts = useSelector((state) => state.posts);
console.log(posts);
return (
<div>
<h1>App</h1>
</div>
);
}
In the above code, the console.log
shows the data twice in the google console, whenever the App.js
is refreshed.
How to make it run only once?