How I understood was that they are basically the same providing devs multiple ways to do the same thing depending on your need.
So if you don't need to use previous state or props, then go with option 1 else option 2.
Unrelated to the main question,
For memoization in React Hooks, they have two different ways to memoize (useCallback & useMemo, which do the same thing but useCallback is called like Option 1 of setState, while useMemo is called like Option 2 of setState).
Official doc shows that
useCallback(fn, inputs) is equivalent to useMemo(() => fn, inputs).
But I don't know enough history about React why there is only setState but two for memoization 😅
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Yikes.. I am sorry I misunderstood the question 😰
How I understood was that they are basically the same providing devs multiple ways to do the same thing depending on your need.
So if you don't need to use previous state or props, then go with option 1 else option 2.
Unrelated to the main question,
For memoization in React Hooks, they have two different ways to memoize (useCallback & useMemo, which do the same thing but
useCallback
is called like Option 1 ofsetState
, whileuseMemo
is called like Option 2 ofsetState
).Official doc shows that
But I don't know enough history about React why there is only
setState
but two for memoization 😅