question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Select trigger error when using both MenuItem(s) and mapping over array

See original GitHub issue

Describe the bug Combining MenuItem component and mapping over variable triggers tslint error when using Select component

To Reproduce Steps to reproduce the behavior:

    <Select name="test">
      <MenuItem value={-1}>Option #1</MenuItem>
      {options.map((o) => (
        <MenuItem value={o.id} key={o.id}>
          {o.name}
        </MenuItem>
      ))}
    </Select>

which gives me this error

Type ‘Element[]’ is missing the following properties from type ‘ReactElement<any, string | ((props: any) => ReactElement<any, string | … | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)>’: type, props, keyts(2739)

Expected behavior I expected to not get an error (i get none if i use TextField component set to select or if i use Select directly from material-ui

Additional context doing this work, but it feels wrong

    <Select name="test">
      {[
        <MenuItem value={-1}>Option #1</MenuItem>,
        ...options.map((c) => (
          <MenuItem value={o.id} key={o.id}>
            {0.name}
          </MenuItem>
        )),
      ]}
    </Select>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
lookfirstcommented, Dec 20, 2020

Thanks and apologies for not ‘getting it’ at first. =)

0reactions
jhammersholtcommented, Dec 20, 2020

Thanks and apologies for not ‘getting it’ at first. =)

Thanks, works for me as well 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - MUI Select custom MenuItem not working properly
Expected behavior: when I click on the MenuItem , it gets selected in the Select component. Actual behavior: nothing happens. The thing is,...
Read more >
Angular directives for Bootstrap - AngularUI
This repository contains a set of native AngularJS directives based on Bootstrap's markup and CSS. As a result no dependency on jQuery or...
Read more >
Lists and Keys - React
In React, transforming arrays into lists of elements is nearly identical. ... Below, we loop through the numbers array using the JavaScript map()...
Read more >
list - Manual - PHP
Like array(), this is not really a function, but a language construct. list() is used to assign a list of variables in one...
Read more >
FactoryTalk View Machine Edition User's Guide
No patent liability is assumed by Rockwell Automation, Inc. with respect to use of information, circuits, equipment, or software described in this manual....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found