React Redux 不传递数据
React Redux not passing data
我正在尝试使用 Redux 学习 React。
作为初学者工具包,我选择了 "react-redux-universal-hot-example"
我正在尝试创建一个显示一些数据的新页面。我密切关注 Widgets 页面,但由于某些原因我的页面显示没有数据。
这是我所做的:
我创建了一个新容器:
Outfits.js
向 API 文件夹添加了操作:
load.js
添加了 Redux 模块 outfits.js
一定是我遗漏了一些相对较小的东西,但我不知道是什么。
经过我修改的整个项目在这里:
https://github.com/zunperior/wear4cast
@asyncConnect
装饰器不会替换 @connect
装饰器。您正在使用 asyncConnect 在需要时加载数据,但没有将商店中的数据连接到组件。您需要在第 3 行取消注释 importing connect,然后使用它将您的 props 连接到 redux store。
@asyncConnect([{
deferred: true,
promise: ({store: {dispatch, getState}}) => {
if (!isLoaded(getState())) {
return dispatch(loadOutfits());
}
}
}])
@connect(
state => ({
outfits: state.outfits.data,
error: state.outfits.error,
loading: state.outfits.loading
}),
{}
)
export default class Outfits extends Component {
static propTypes = {
outfits: PropTypes.string,
error: PropTypes.string,
loading: PropTypes.bool
};
// ...
}
我正在尝试使用 Redux 学习 React。 作为初学者工具包,我选择了 "react-redux-universal-hot-example"
我正在尝试创建一个显示一些数据的新页面。我密切关注 Widgets 页面,但由于某些原因我的页面显示没有数据。
这是我所做的:
我创建了一个新容器: Outfits.js
向 API 文件夹添加了操作: load.js
添加了 Redux 模块 outfits.js
一定是我遗漏了一些相对较小的东西,但我不知道是什么。
经过我修改的整个项目在这里: https://github.com/zunperior/wear4cast
@asyncConnect
装饰器不会替换 @connect
装饰器。您正在使用 asyncConnect 在需要时加载数据,但没有将商店中的数据连接到组件。您需要在第 3 行取消注释 importing connect,然后使用它将您的 props 连接到 redux store。
@asyncConnect([{
deferred: true,
promise: ({store: {dispatch, getState}}) => {
if (!isLoaded(getState())) {
return dispatch(loadOutfits());
}
}
}])
@connect(
state => ({
outfits: state.outfits.data,
error: state.outfits.error,
loading: state.outfits.loading
}),
{}
)
export default class Outfits extends Component {
static propTypes = {
outfits: PropTypes.string,
error: PropTypes.string,
loading: PropTypes.bool
};
// ...
}