1

Both of the following work and the child component doesn't rerender, but which one is preferable and why?

This one using a const and an updater function

const [count, setCount] = useState(0)
const increment = useCallback(() => {
    setCount(c => c + 1)
}, [])

Or this one using a let and a ++ operator

let [count, setCount] = useState(0)
const increment = useCallback(() => {
    setCount(count++)
}, [])
Squirrl
  • 4,909
  • 9
  • 47
  • 85
  • 1
    Always `const` since the only way to change its value should be using `setCount`, never changing it "manually" – Rashomon Nov 18 '21 at 11:03

0 Answers0