Hi, My front-end is like this.
I fetch data from my backend and test it by using console.log. I don’t know why the console.log gets executed two times as it shows in my Chrome console?
FYI, I use isLoaded
as a flag to determine whether State has been set.
Thanks for any opinions.
For future posts, it would be much more useful if you posted some code, or a link to your project on CodePen, jsFiddle, or similar.
This was also discussed somewhat here: Simple React Component Renders twice when using the useState hook
I suspect it is an issue with the way most online editors render. That being said, if you are hosting locally, and rendering using something like create-react-app, then I am not sure why your component would be rendered twice.
@Nodemon you should put console.log before the return statemen to see how many times it render.