我在我的项目中使用 ustated 库。
在渲染方法中,我是这样使用set
的:
render() {
return (
<ApiSubscribe>
{api => (
<button content='CLICK ME' onClick={() => api.setMessage('RENDER CLICK')} />
)}
</ApiSubscribe>
)
}
我如何调用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>;
};