mobx: 5.03 react: 16.4.1 mobx-react: 5.2.3 rails: 5.0.2 react-rails gem
I have a basic mobx setup in react. I am trying to get the rowData observable variable to change in the view after an http request. However, once it is rendered at the default "111" it always stays at that value. How can I get mobx to update the Component render?
import React from "react"
import axios from 'axios'
import { decorate, observable, computed, action } from "mobx"
import { observer } from "mobx-react"
class Device extends React.Component {
rowData = 111 //view always stays at this value
componentDidMount() {
axios.get("/projects.json")
.then(response => { this.rowData = 555 })
.then(() => console.log(this.rowData)) //logs 555
}
render() {
return (
<div>
{this.rowData}
</div>
);
}
}
decorate(Device, {
rowData: observable
})
export default observer(Device);