Checking for Undefined In React
问题 I have a scenario where I'm passing data from a reducer into my react state. data: { "id": 1, "title": "Test", "content": { "body": "sdfsdf" "image": "http://example.com" } } Using componentWillRecieveProps, this works perfectly for retrieving the title. componentWillReceiveProps(nextProps) { this.setState({ title: nextProps.blog.title, }) } However, I'm having difficulty retrieving the nested fields. When I do this: componentWillReceiveProps(nextProps) { console.log("new title is", nextProps