Pay attention
This documentation is for the as yet unreleased version of effector Spacewatch 23.0.

useStore

[ ru ]

React hook, which subscribes to a store and returns its current value, so when the store is updated, the component will update automatically.

Formulae

useStore(store: Store<T>): T

Arguments

  1. store: Store

Returns

(State): The value from the store

Example

import { createStore, createApi } from "effector";
import { useStore } from "effector-react";

const $counter = createStore(0);

const { increment, decrement } = createApi($counter, {
  increment: (state) => state + 1,
  decrement: (state) => state - 1,
});

const App = () => {
  const counter = useStore($counter);

  return (
    <div>
      {counter}
      <button onClick={increment}>Increment</button>
      <button onClick={decrement}>Decrement</button>
    </div>
  );
};

Try it

Contributors