JavaScript React Components Managing State and Data Flow Update State Based on a Player's Index

onClick 1 and -1 to 0.5 and -0.5 otherwise increment by 2???

In the Counter I had to change the 1 and -1 to 0.5 and -0.5 because otherwise on click the score would increment by 2. Any ideas why this happened?

3 Answers

Oliver Duran
seal-mask
.a{fill-rule:evenodd;}techdegree
Oliver Duran
Full Stack JavaScript Techdegree Student 16,241 Points

Hey Marius! i fixed that problem by removin this from the index.js file, i do not know why but it worked!

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);

ReactDOM.render(
    <App />,
  document.getElementById('root')
);
John Lamontagne
John Lamontagne
3,201 Points

Thanks for this, it seems like some weird code that Treehouse has put in.

Brian Beal
Brian Beal
5,300 Points

It's an intentional feature of the StrictMode. This only happens in development, and helps find accidental side effects put into the render phase. We only do this for components with Hooks because those are more likely to accidentally have side effects in the wrong place.

https://github.com/facebook/react/issues/15074