Skip to content

Latest commit

 

History

History
27 lines (17 loc) · 545 Bytes

File metadata and controls

27 lines (17 loc) · 545 Bytes

useAtom

An utility function that that can be used to get and set the value

Definition

Accept one generic argument for typing the value.

@param initalValue - The initial value of the atom.

@returns A function that takes an optional parameter and returns a value.

Usage

const name = useAtom<string>("hello");

return (
    <div>
      <span>Name: "{name()}"</span><br/>
      <button onClick={() => name('Mike')}>Set into "Mike"</button>
      <button onClick={() => name('Luca')}>Set into "Luca"</button>
    </div>
)