reactjs - Redux get store.getState() 未定义
问题描述
我正在从反应中的常规有状态组件迁移到减少。当我尝试console.log store.getState()
在返回函数中运行时,它显示为未定义状态。我不确定我在这里做错了什么。任何帮助将非常感激!
const store = createStore(reducers, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__());
class Products extends React.Component {
constructor (){
super();
this.state = {
productImages: [],
fetching: false
}
}
componentDidMount(){
this.setState({
fetching: true,
});
fetch('https://omenu.com/test/jsonimages')
.then(response => response.json())
.then(products => products.map(product => product.image))
.then(products => store.dispatch(addLink(products)))
.catch(err => console.log(err))
}
render(){
return(
<Provider store={store}>
{console.log(store,"Store")} //having a problem here ----- It showing undefined
<ScrollView horizontal={true}>
<ActivityIndicator size="large" style={styles.spinner} animating={true}/>
{this.state.productImages.map((uri,i)=>(
<Image style={styles.thumb} key={i} source={{uri}}/>
))}
</ScrollView>
</Provider>
)
}
}
解决方案
推荐阅读
- twitter-bootstrap-3 - 即使格式化,Bootstrap3 datetimepicker 也会显示日历?
- python - 试图找到 FP,FN,TP,TN 但我遇到了一些错误
- automation - 我在 MOCHA-Chai 的调用 API 中使用了断言
- asp.net-core - 错误请求,标头太长,错误代码 400(使用 IIS 服务器 .netCore 应用程序运行)
- asp.net-mvc - 将 EditFor 替换为复选框
- python - IMDB 数据集示例上的 Keras 网络错误。不兼容的形状
- git - 如何在 Azure DevOPS 服务器上使用 PAT 克隆 git 存储库
- vue.js - 使用地址查找时vuejs模型不更新
- excel - 如果窗口被锁定,宏不会循环
- flutter - 在 Flutter 的 ListView 中填充生成的动态数据