Documents / @faasjs/react / useStateRef
Function: useStateRef()
useStateRef<
T
>(initialValue
?): [T
,Dispatch
<SetStateAction
<T
>>,RefObject
<T
>]
Custom hook that returns a stateful value and a ref to that value.
Type Parameters
• T = any
The type of the value.
Parameters
initialValue?
T
The initial value of the state.
Returns
[T
, Dispatch
<SetStateAction
<T
>>, RefObject
<T
>]
- The stateful value, a function to set the value, and a ref to the value.
Example
import { useStateRef } from '@faasjs/react'
function MyComponent() {
const [value, setValue, ref] = useStateRef(0)
return (
<div>
<p>Value: {value}</p>
<button onClick={() => setValue(value + 1)}>Increment</button>
<button onClick={() => console.log(ref.current)}>Submit</button>
</div>
)