import React, { useReducer } from 'react'
const reducer = (state, action) => {
console.log(action.type);
switch (action.type) {
case 'inc': return state + 1
default: return state
}
}
function App() {
const [counter, dispatch] = useReducer(reducer, 0)
const countUp = () => (
dispatch({ type: 'inc' })
)
console.log('render');
return (
<div>
<h2>{counter}</h2>
<button onClick={countUp}>Count up</button>
</div>
)
}
export default App
Why when i click on Count up button (App component) re-render and log 'render string' to the console twice?
Is that a normal behavior?