Just getting started with Mobx & React and having trouble getting the store to update. I get error when clicking the button, which should update the 'me' property:
Store.js:12 Uncaught TypeError: Cannot set property 'me' of null
My store:
import { observable } from 'mobx';
class Store {
@observable me;
constructor() {
this.me = 'test';
}
change_me(){
this.me = 'test 1';
console.log(this); // null???
}
}
const store = new Store();
export default store;
The component:
import React from "react";
import { observer } from 'mobx-react';
export default class Layout extends React.Component{
render(){
var store = this.props.store;
return(
<div>
<button onClick={store.change_me}>{store.me}</button>
</div>
)
}
}
I've probably missed some fundamental part of how this works, but can't figure it out.