import { createGate, type Gate } from "effector-react";
Methods
createGate(name?)
Creates a Gate
Formulae
createGate(name?: string): Gate<T>
Arguments
name?
(string): Optional name which will be used as the name of a created React component
Returns
Examples
Basic Usage
import React from "react";
import ReactDOM from "react-dom";
import { createGate } from "effector-react";
const Gate = createGate("gate with props");
const App = () => (
<section>
<Gate foo="bar" />
</section>
);
Gate.state.watch((state) => {
console.log("current state", state);
});
// => current state {}
ReactDOM.render(<App />, document.getElementById("root"));
// => current state {foo: 'bar'}
ReactDOM.unmountComponentAtNode(document.getElementById("root"));
// => current state {}
createGate(config?)
Creates a Gate, if defaultState
is defined, Gate.state will be created with passed value.
Formulae
createGate({ defaultState?: T, domain?: Domain, name?: string }): Gate<T>
Arguments
config
(Object): Optional configuration object
defaultState?
: Optional default state for Gate.statedomain?
(Domain): Optional domain which will be used to create gate units (Gate.open event, Gate.state store, and so on)name?
(string): Optional name which will be used as the name of a created React component