1

反応フォームを使用して単純なフォームを作成し、アイテムのリストをコンポーネントに渡したいと考えていSelectます。Selectコンポーネントはreact-formライブラリの一部です。

fooItemsに aを渡したいSelect

Selectコンポーネントに必要な構造

selectItems = [{
  value: 1,
  label: 'a',
}, {
  value: 2,
  label: 'b',
}]

fooItemsまず、Redux から受け取った配列をフィルタリングしたいmapStateToProps

fooItems = [{
  id: 1,
  name: 'a',
  parent: 'P',
  child: 'C'
}, {
  id: 2,
  name: 'b',
  parent: 'P',
  child: 'C'
}]

小道具をコンポーネントに渡しながら関数を実装しようとしています

render() => (
    <Select
    field = "foo"
    id = "foo"
    options = {
      () => {
        return this.props.fooItems.map(e => {
          return {
            label: e.name,
            value: e.id
          }
        })
      }
    }
    />)

しかし、次のエラーが発生します

Uncaught TypeError: Cannot read property 'find' of undefined
at t.value (index.js:1)

The above error occurred in the <t> component:
in t (created by r)
4

1 に答える 1