I didnt expect the child component to re-render because i didnt pass the increaseSecondState function as a prop to the child component. Because we all know after using React.memo on the child component, the only way it can re-render is if only its prop changes.
import React, { useState, useCallback } from 'react'
import Child from './Child'
function Example() {
const [state, setState] = useState(0)
const [count, setCount] = useState(0)
const increaseFirstState = () => {
setState(state + 1)
}
const increaseSecondState = () => {
setCount(count + 1)
}
return (
<div>
<Child firstFunc={increaseFirstState} />
<h1>first state - {state}</h1>
<h1>second state - {count}</h1>
<button onClick={increaseFirstState}>first state</button>
<button onClick={increaseSecondState}>second state</button>
</div>
)
}
export default Example