0
私は、EditFieldコンポーネントにpropsを渡すオブジェクトのキーにアクセスできません。私がプロップをログに記録すると、オブジェクトに正しく出力されますが、オブジェクトのキーを取得しようとすると「未定義エラー」が発生します。そのオブジェクトはどうなっていますか?オブジェクトのプロパティにアクセスできない
class EditForm extends React.Component {
render() {
const departments = this.props.departments
const showcasedDepName = this.props.showcasedDepName
const dep = departments.filter(dep => dep.depName ===
showcasedDepName)[0]
return(
...irrelevant stuff
<EditField department={dep}/>
</form>
</div>
)
}
}
EditFieldコンポーネントを:
class EditField extends React.Component {
render() {
const department = this.props.department
console.log(department.depName) //"undefined", whereas it shows me the correct object when I do console.log(department)
return(
<div className="edit-dep">
<div>Department name: <input type="text" value=
{department.depName}/></div>
</div>
)
}
}
オブジェクトの構造を追加できますか? console.log(department [0] .depName) –
が投稿に追加されました – Umbrella
console.logを試してください。 EditFormコンポーネントのレンダリングメソッドで 'dep'定数の最後に[0]を置いたのでオブジェクトです。 –