score:1
It is because of React.StrictMode
If you go to your index.js , you will find that your App
component is wrapped with <React.StrictMode>
. If you strip off the StrictMode you will notice that your App
component will render only once.
Refer the below doc to understand StrictMode
Strict mode can’t automatically detect side effects for you, but it can help you spot them by making them a little more deterministic. This is done by intentionally double-invoking the following functions:
Class component constructor, render, and shouldComponentUpdate methods Class component static getDerivedStateFromProps method Function component bodies State updater functions (the first argument to setState) Functions passed to useState, useMemo, or useReducer
Please refer: https://reactjs.org/docs/strict-mode.html
score:-1
return (<React.StrictMode><App /><React.StrictMode>)
This would solve your problem.
Source: stackoverflow.com
Related Query
- How does React useState hook work with mutable objects
- How does React useState and useCallback hook work when useCallback lacks dependencies
- How does this useState hook work in React?
- How does this React code work on CodePen even if no preprocessor is selected?
- How does React hook useRef() work under the hood? What is that reference exactly?
- React JS - How does this function work to delete JSON data?
- how to create a custom hook on react for this current useState usage
- how does promise and useState really work in React with AWS Amplify?
- How does react useEffect work with useState hook?
- How does setState in React work in this scenario?
- How does useState hook know the calling context in react
- How does prevState in new useState in React work ?? How does it store the value of previous state?
- How to use callback with useState hook in react
- How does shallow compare work in react
- How to prevent race conditions with react useState hook
- How to use React Context with useState hook to share state from different components?
- how can I test if useState hook has been called with jest and react testing library?
- React Hook does not work properly on the first render in gatsby production mode
- How does Express and React Routes work on initial GET request from browser?
- How does React State Hook gets the state variable name from the ES6 Destructuring Assignment
- useState react hook does not set the array state
- How to change/add value of a certain row of an array using useState Hook in React
- How does React Context work by using a function inside of a component
- How does this React example work?
- how does the .render() function in react work internally?
- How to use useState hook in React with typescript correctly?
- How does this arrow function work in my special case passing it through Redux
- Why ES6 ComputedPropertyName does not work with this react js code?
- angular scope vs react state how does it work for data binding
- Can't make this message hook work in React
More Query from same tag
- How to show the content and hide the content conditionally in react using hooks
- Firestore onSnapshot updates and adds array to the DOM instead of only updating
- Uncaught TypeError: Cannot read property 'map' of undefined in reactjs
- Show or hide Carousel item depending on index | React
- This is driving me crazy - Line 42:40: 'firebase' is not defined no-undef
- SyntaxError: expected expression, got '<' using dojo toolkit 1.6
- Automate requests to API for CRUD components in React?
- Mock Bing Maps API with Jest in React.js
- Webpack bundle splitting produces empty bundle.js
- Warning: Functions are not valid as a React child HOC
- How to transfer states among components?
- multiple package.json files in react nodejs project
- React JSX class library exports are not working
- Sending Request body for GET method in AXIOS throws error
- React list, show active item onClick. Without re-rendering the list
- React SVG Manipulation [Electron] (change color if DB is connected)
- Apollo query loading is always false
- how do you specify a class function to use typescript props interface
- Change position of text over a card image: Bootstrap
- DataTables.net in React - Tooltip on header column cell needed
- get the random generated string in javascript function from website
- React Hooks useState useEffect slideshow
- Enable only one submit button in an iteration
- Combine two switch/case statements in React component
- Triggering specific function on state change
- GraphQL playground returns data, while app returns null
- React Router 6 Nest Routes
- How to implement Counter on each item in the FlatList
- React.js setState issue
- Update App state based on Child component