altjs 反应商店连接不工作
altjs react store connection not working
我正在尝试将我的商店连接到实际的应用程序,以便提供数据并对状态变化做出反应。遗憾的是,商店连接似乎有问题。
@connectToStores
class App extends Component {
static getStores() {
return [CategoryStore, UserStore, LocalizationStore];
}
static getPropsFromStores() {
return {
...CategoryStore.getState(),
...UserStore.getState(),
...LocalizationStore.getState()
};
}
static componentDidConnect(props, context) {
ca.fetchCategories();
la.fetchLocales();
}
在 运行 项目中永远不会使用 componentDidConnect。据此:https://github.com/altjs/connect-to-stores/issues/6 商店连接后,该功能应该 运行。
我让它部分地工作,将动作放在 componentWillMount 中,但状态没有正确更新。所以我认为商店连接设置不正确。
ES7装饰器/ES6正常实现我也都试过了
我不知道为什么商店的数据没有正确分发。非常欢迎任何帮助!
我明白了。道具没有传给子孙的原因如下:
我用它来初始化 children:
const children = React.Children.map(this.props.children, (child) => {
return React.cloneElement(child, this.state);
});
它传递状态而不是道具。因此用 this.props 替换 this.state 对我有用。
我正在尝试将我的商店连接到实际的应用程序,以便提供数据并对状态变化做出反应。遗憾的是,商店连接似乎有问题。
@connectToStores
class App extends Component {
static getStores() {
return [CategoryStore, UserStore, LocalizationStore];
}
static getPropsFromStores() {
return {
...CategoryStore.getState(),
...UserStore.getState(),
...LocalizationStore.getState()
};
}
static componentDidConnect(props, context) {
ca.fetchCategories();
la.fetchLocales();
}
在 运行 项目中永远不会使用 componentDidConnect。据此:https://github.com/altjs/connect-to-stores/issues/6 商店连接后,该功能应该 运行。 我让它部分地工作,将动作放在 componentWillMount 中,但状态没有正确更新。所以我认为商店连接设置不正确。
ES7装饰器/ES6正常实现我也都试过了
我不知道为什么商店的数据没有正确分发。非常欢迎任何帮助!
我明白了。道具没有传给子孙的原因如下:
我用它来初始化 children:
const children = React.Children.map(this.props.children, (child) => {
return React.cloneElement(child, this.state);
});
它传递状态而不是道具。因此用 this.props 替换 this.state 对我有用。