I am tring to use the Mobx to manage my react-project's state,but I cannot get the props from the Provider by mobx-react.
This is my root element(I delete the router to simplify the question):
import React from "react";
import ReactDOM from "react-dom";
import {Router, Route, hashHistory} from "react-router";
import {Provider} from "mobx-react";
import store from "../store";
import App from "./app";
ReactDOM.render((
<Provider store={store}>
<App/>
</Provider>),
document.getElementById("content"));
and this is my childNode:
import React, {Component} from "react";
import {observer, inject, PropTypes} from "mobx-react";
@inject("store") @observer
export default class App extends Component {
constructor(props) {
super(props);
console.log(this.props.store);
}
render() {
return (
<div>
ab
</div>
)
}
}
App.propTypes = {
store: PropTypes.observableObject
};
But when I log the store,the result is undefined, and I don't know why I cannot get the store.
From the chrome devtools, I find the Provider has the store but App cannot get store,I am very confused.
My store is bellow:
import {observable} from "mobx";
class Store {
@observable count;
constructor() {
this.count = 1;
}
addCount() {
this.count += 1;
}
decreaseCount() {
this.count -= 1;
}
}
let store = new Store();
export default store;