0

I am trying to populate select in [stateless component of] React/Redux app as:

const FillSelect = ({team}) => <option value={team.onboardingOrder}>{team.name}</option>

const TeamSelector = ({teams}) => {
  return (
    <select>
      <option value="">All</option>
      {
        teams ? (teams => teams.map(team => <FillSelect team={team} />)) : null
      }
    </select>
  )
}

Teams looks like:{0:{id: 1, name: "Program Management", onboardingOrder: 0, …}, 1: {id: 2, name: "Value Capture", onboardingOrder: 1, …}…}.

It returns an error: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it. in select ...

Is this happening because I am using map()? What is the correct way of doing this?

2

2 Answers 2

3

You're not calling map directly; if teams is truthy, you return a function (teams => ...). You probably wanted the line to look like this:

teams ? teams.map(team => <FillSelect team={team} />) : null

Which would yield an array of <FillSelect />'s.

Sign up to request clarification or add additional context in comments.

1 Comment

Did not make any difference.
0

This works fine:

  return (
    <select>
      <option value="">All</option>
      {
        Object.values(teams).map((team, i) => <option value={team.onboardingOrder} key={i}>{team.name}</option> )
      }
    </select>
  )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.