我正在从React中的常规有状态组件迁移到Redux。当我尝试在return函数中运行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>
)
}
}