github statelyai/xstate @xstate/store@3.7.0

2 months ago

Minor Changes

  • #5302 809d8b5 Thanks @davidkpiano! - The useAtom hook is now available for reading the value of an atom or selecting a value from the atom.

    const atom = createAtom(0);
    
    const Component = () => {
      const count = useAtom(atom);
    
      return (
        <>
          <div onClick={() => atom.set((c) => c + 1)}>{count}</div>
          <button onClick={() => atom.set(0)}>Reset</button>
        </>
      );
    };

    With selectors:

    const atom = createAtom({ count: 0 });
    
    const Component = () => {
      const count = useAtom(atom, (s) => s.count);
    
      return <div>{count}</div>;
    };

Don't miss a new xstate release

NewReleases is sending notifications on new releases.