标签: unstated

如何在render方法之外使用react unstated?

我在我的项目中使用ustated库。

在渲染方法中,我这样使用set

render() {
    return (
            <ApiSubscribe>
                {api => (
                    <button content='CLICK ME' onClick={() => api.setMessage('RENDER CLICK')} />
                )}
            </ApiSubscribe>
    )
}
Run Code Online (Sandbox Code Playgroud)

如何api.setMessage在渲染外调用?例如在componentDidMount

ApiSubscribe是:

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>;
};
Run Code Online (Sandbox Code Playgroud)

reactjs unstated

6
推荐指数
1
解决办法
1027
查看次数

标签 统计

reactjs ×1

unstated ×1