I am trying to add mobx to an existing project. The project was bootstraped with create-react app, ejected and then I added mobx on top of it. This is my store so far:
import {observable, action, computed} from 'mobx'
export default class timerStore {
@observable message = 'THIS IS FROM THE STORE'
constructor(count, message) {
this.message = message;
}
}
I am passing the store to my app in the index component:
render(
(<Provider timerStore={timerStore}>
<Router history={hashHistory}>
<Route component={Main} path="/">
<IndexRoute component={Tea}/>
<Route component={About} path="/about"/>
<Route component={Timer} path="/timer"/>
</Route>
</Router>
</Provider>
),
document.querySelector('#root')
);
And then I am trying to reference it in the Timer component:
@inject("timerStore")
@observer
class Timer extends Component {
render() {
const { message } = this.props.timerStore
return(
<div className="content-card timer-card">
<h1 className="title">Tea timer {message}</h1>
</div>
)
}
}
export default Timer;
But the message string is not being shown, and when I check it in the debugger (this.props.timerStore.message), it is showing as undefined.
It is also showing this.props.timerStore as a function that takes count, message as argument.
What am I doing wrong?
I cleared most of the application logic to keep the example simple. If any information needed to help here is missing, please let me know and I will update the question.