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

createComponent

createComponent(store, render)

Creates a store-based React component. The createComponent is useful for transferring logic and data of state to your View component.

since

You can use hooks in createComponent since effector-react@20.3.0.

Arguments

  1. store (Store | Object): Store or object of Store
  2. render (Function): Render function which will be called with props and state

Returns

(React.Component)

Example

import { createStore, createEvent } from "effector";
import { createComponent } from "effector-react";

const increment = createEvent();

const $counter = createStore(0).on(increment, (n) => n + 1);

const MyCounter = createComponent($counter, (props, state) => (
  <div>
    Counter: {state}
    <button onClick={increment}>increment</button>
  </div>
));

const MyOwnComponent = () => {
  // any stuff here
  return <MyCounter />;
};

Try it

Contributors