更改存储后,React Mobx组件不会更新

时间:2017-06-30 09:58:01

标签: reactjs meteor mobx mobx-react

我想在我的React App中创建全局通知组件。我添加了 mobx-react 来创建Notification商店:

class NotificationStore {
  @observable message = '';
  @observable isActive = false;
}

const store = new NotificationStore;

export default store;

我的组件,在我的布局中添加:

@observer
class NotificationBox extends Component {

  render() {
    return (
      <h1>{this.props.store.message}</h1>
    );
  }
}

export { NotificationBox };

我的布局:

<NotificationBox store={store} />

我的代码用于更新我的商店(例如发送表单):

<a onClick={this.update}>Update my store</a>

update() {
  store.message = 'My new message !';
  store.isActive = true;
}

此示例更新了我的商店,但我的通知组件视图未更新。我不知道为什么:(

有人有想法吗?

谢谢社区!

0 个答案:

没有答案
相关问题