我正在尝试将数据传递给子组件,并且不断收到未定义的道具。我认为当Im在父组件中设置状态时可能会遇到问题。我应该不使用componentWillMount吗?为什么我的道具未定义,当我通过一个已定义的状态?
export default class AllItems extends Component {
constructor() {
super()
this.state=({ user: cookie.load('user')})
this.httpHandler = axios.create({
baseURL: 'http://localhost:3000/',
headers: {
'Authorization': this.state.user.token
}
})
}
componentWillMount() {
this.httpHandler('/products/')
.then(function (response) {
this.setState({ winks: response.data.data})
console.log(this.state.winks)
}.bind(this))
}
render() {
return (
<Winks products={this.state.winks} />
)
}
}