0

I've a simple child component that have string props, and why is it rendered twice at first laod?

export default function App() {
  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <h2>Start editing to see some magic happen!</h2>
      <MyChild a={1} b={2} />
    </div>
  );
}

const MyChild = ({ a, b }) => {
  console.log("hi"); //called twice?
  return <h1>hi</h1>;
};

demo https://codesandbox.io/s/wizardly-lamport-pesw42?file=/src/App.js

Alicia Y
  • 367
  • 5
  • 12

1 Answers1

0

https://codesandbox.io/s/suspicious-curran-rbyyhn?file=/src/index.js

Remove StrictMode in index.js.

It makes react render twice

Taehyun Hwang
  • 232
  • 1
  • 2
  • 10