In this case I'm sending same props and state for Child component, so... why has not re-render without React.memo()
and those logs show just once?
import React, { useState } from 'react';
import ReactDOM from 'react-dom';
const Child = ({ num }) => {
const [count, setCount] = useState(0);
return (
<>
{console.log('Child rendered')}
{count}<br />
{num}<br />
<button onClick={() => setCount(count)}>Add</button>
</>
)
}
const App = () => {
const [num, setNum] = useState(0);
return (
<>
{console.log('App rendered')}
<Child num={num} />
<button onClick={() => setNum(num)}>Add</button>
</>
)
}
ReactDOM.render(
<App />,
document.getElementById('root')
);