Closed stukennedy closed 8 years ago
I'm wanting to silently set state on the store without triggering listeners.
An example of my Store
import alt from './alt' import AppActions from './AppActions' class AppStore { constructor () { this.bindActions(AppActions) this.state = { forms: {} } } initForms (data) { this.state.forms = data } } export default alt.createStore(AppStore, 'AppStore')
My Component
import React from 'react' import AppStore from '../AppStore' import AppActions from '../AppActions' let { Component } = React export default class Input extends Component { componentDidMount () { AppStore.listen(data => { console.log('forms changed', data.forms) }) AppActions.initForms({foo: "bar", bar: "foo"}) } render () { return <div>Hello</div> } }
Why is my listener being triggered when I use this.state on the Store, I thought you needed to use this.setState() to trigger the listeners
this.state
this.setState()
If you return false from your store methods like initForms, it will not trigger the listeners. It's here in the docs.
initForms
thanks so much, completely missed that
I'm wanting to silently set state on the store without triggering listeners.
An example of my Store
My Component
Why is my listener being triggered when I use
this.state
on the Store, I thought you needed to usethis.setState()
to trigger the listeners