Should I use an updater function and const in a useCallBack or a let variable?

Viewed 16

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++)
}, [])
0 Answers
Related