我只是试图将商店包含的内容显示为列表。当我尝试显示商店的属性时,它显示为空白。我使用console.log作为属性,它说它是未定义的。
对象:
export default function(){
return(
{
id:'1',
name: 'John',
lastname: 'Poo',
img: '../public/assets/astro.jpg',
About: 'Here to dance!'
}
)
}
减速器:
import { combineReducers, configureStore } from 'redux'
import ABOUTME from '../shared/AboutMe'
export const allReducers = combineReducers({
aboutme: ABOUTME,
})
App.js:
import { Provider } from 'react-redux';
import {createStore} from 'redux'
import {allReducers} from './redux/reducer.js'
import Main from './components/MainComponent'
const store = createStore(allReducers)
class App extends Component {
render(){
console.log(store.name)//shows undefined
return (
//Step5: wrap your whole components with provider
<Provider store={store}>
<BrowserRouter>
<h1>Why this is not working</h1>
<Main/>
</BrowserRouter>
</Provider>
);
}
}
export default App;
和我的主文件:
import {connect} from 'react-redux'
import React, {Component} from 'react'
import { Switch, Route, Redirect, withRouter } from 'react-router-dom';
const mapStateToProps = (state) =>{
return{
aboutme: state.aboutme
}
}
const JustPrint = (value) => {
//shows undefined, hence enters the else statment
console.log(value.name)
if(value.name !== undefined){
return(
<li>{value.name}</li>
)
}
else{
return(
<li>value is not defined</li>
)
}
}
class Main extends Component{
constructor(props){
super(props)
}
render(){
return(
<div>
<h1>This is my list</h1>
<JustPrint value={this.props.aboutme} />
</div>
)
}
}
export default withRouter(connect(mapStateToProps)(Main));
当我console.log(value)显示对象时,但我无法访问其属性
一个多星期以来,我一直在尝试各种视频,教程和方法,但是没有办法解决这个问题。任何帮助将不胜感激。