Returns a computable stateful value, and a function to update it. useComputedState will only recompute the state when one of the dependecies has changed. If no dependecies array is provided, a new value will be computed on every render.
dependecies
import {useComputedState} from 'react-hooks'const Component = ({defaultName}: {defaultName: string}) => { const [name, setName] = useComputedState(() => defaultName, [defaultName]) const handleChange = (event) => setName(event.target.value) return ( <> {name} <input onChange={handleChange} value={name} /> </> )}
A function that computes and returns the next state.
An optional array of dependecies that triggers the computation of the next state.
React hook to simplify the use of asynchronous operations.
import {usePromise} from 'react-hooks'const Component = () => { const {data} = usePromise(async () => 1, []) return <>{data.toString()}</>}
A function that returns a promise.
Generated using TypeDoc
Returns a computable stateful value, and a function to update it. useComputedState will only recompute the state when one of the
dependecies
has changed. If nodependecies
array is provided, a new value will be computed on every render.