useCurrentState
Get the latest value in functional component. By default, state
in a React function component
can only get the value at render time, not the latest.
This is a small tool to get the latest value, It is very useful in async actions such as setTimeout
.
if you like a bigger solution,
try useReducer.
This is custom React hooks, you need to follow the Basic Rules when you use it.
General
Code Editor
Code Editor
APIs
useCurrentState
type CurrentStateType<S> = [
S,
Dispatch<SetStateAction<S>>,
MutableRefObject<S>,
]
const useCurrentState<S> = (
initialState: S | () => S,
) => CurrentStateType<S>
Contributors
Geist is an open source project from the community.
And is powered by Netlify.