Generating SelectField options

Hello

I’m fairly new to RedwoodJS and so far I really like it.

Right now I’m trying to get the SelectField form component to list the users which I get from a query.

<SelectField
        name="executorId"
        defaultValue={props.note?.executorId}
        className="rw-input"
        errorClassName="rw-input rw-input-error"
        validation={{
          required: true,
        }}
      >
        {users.map((user) => (
          <>
            <option key={user.id} value={user.id}>
              {user.name} ({user.email})
            </option>
          </>
        ))}
      </SelectField>

The users get loaded correctly and they also are shown in the dropdown.

My problem is, that i get the following error:

Warning: Each child in a list should have a unique "key" prop.

I assigned a key value to each <option>, am I missing something?

Thanks!

1 Like

you are enclosing the option in a fragment, that’s what doesn’t have a key

you don’t need that fragment <></> because you are returning only one thing from your map

try getting rid of the fragment [wrapper]

cheers & welcome to Redwood

Al;

  • Redwood Rules !
1 Like