createGate

createGate(config?: {defaultState?, name?})

Creates a Gate, if defaultState is defined, Gate.state will be created with passed value

Arguments

config (Object): Optional configuration object

  • defaultState: Optional default state for Gate.state
  • name (string): Optional name which will be used as name of created react component

Returns

Gate

createGate(name?)

Creates a Gate

Arguments

  1. name? (string): Optional name which will be used as name of created react component

Returns

Gate

Example

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 {}

Try it

Last updated on