I recently came across a new definition for useState generics in a TS course, but it was briefly covered and I'm still struggling to fully grasp it.
function useState<S>(initialState: S | (() => S)):
[S, Dispatch<SetStateAction<S>>];
After researching this topic extensively, I have a decent understanding of most aspects of it. However, the
Dispatch<SetStateAction<S>>
part has left me confused. While I see that the type is passed into SetStateAction, I'm unsure about how it functions and what should be designated to Dispatch. I would greatly appreciate a thorough explanation of this concept.