unstated

React - Can you update an Unstated container state from an external function?

久未见 提交于 2019-12-23 17:33:38
问题 In the example from the Unstated library they update state within a container by interacting with a jsx button that is subscribed to the container. import React from 'react'; import { render } from 'react-dom'; import { Provider, Subscribe, Container } from 'unstated'; type CounterState = { count: number }; class CounterContainer extends Container<CounterState> { state = { count: 0 }; increment() { this.setState({ count: this.state.count + 1 }); } decrement() { this.setState({ count: this

How to use react unstated outside of render method?

 ̄綄美尐妖づ 提交于 2019-12-21 13:08:39
问题 I am using ustated library in my project. In render method, I am using set like this: render() { return ( <ApiSubscribe> {api => ( <button content='CLICK ME' onClick={() => api.setMessage('RENDER CLICK')} /> )} </ApiSubscribe> ) } How can I call api.setMessage OUTSIDE of render? For example in componentDidMount ? ApiSubscribe is: export const ApiSubscribe = props => { // We also leave the subscribe "to" flexible, so you can have full // control over your subscripton from outside of the module

How to use react unstated outside of render method?

爷,独闯天下 提交于 2019-12-04 08:38:15
I am using ustated library in my project. In render method, I am using set like this: render() { return ( <ApiSubscribe> {api => ( <button content='CLICK ME' onClick={() => api.setMessage('RENDER CLICK')} /> )} </ApiSubscribe> ) } How can I call api.setMessage OUTSIDE of render? For example in componentDidMount ? ApiSubscribe is: export const ApiSubscribe = props => { // We also leave the subscribe "to" flexible, so you can have full // control over your subscripton from outside of the module return <Subscribe to={props.to || [Api]}>{props.children}</Subscribe>; }; Like this? class Child