Skip to content

Latest commit

 

History

History
17 lines (12 loc) · 386 Bytes

use-const.md

File metadata and controls

17 lines (12 loc) · 386 Bytes

useConst

Returns a constant value over the lifecycle of a component.

Example

const [count, setCount] = useState(123);
const initialState = useConst(state);

useEffect(() => {
  console.log(initialState);
  // => 123 (always — even after invoking setCount)
}, [count])

<button onClick={() => setState((curr) => curr + 1))}>Click me to increment: {count}</button>