<MenuItem> in <Select> won't accept objects as value
See original GitHub issueIt is possible to pass objects to the value of the <Select>
. But the <MenuItem>
won’t accept objects as a value.
let value: ObjectType = {a: 1, b: 2};
<Select value={value}>
<MenuItem value={value}>{value.b}</MenuItem>
</Select>
TS2322: Type 'ObjectType' is not assignable to type 'string | number | string[]'.
I think the MenuItem inherits value from React.LiHTMLAttributes<HTMLElement>
Casting the object to ‘any’ will work, but is possibly not as it is intended.
Expected Behavior 🤔
MenuItem (as Select itself) should accept objects.
Current Behavior 😯
A type error.
Your Environment 🌎
Tech | Version |
---|---|
Material-UI | v3.9.0 |
React | 16.7.0 |
TypeScript | 3.2.4 |
Issue Analytics
- State:
- Created 5 years ago
- Reactions:10
- Comments:11 (4 by maintainers)
Top Results From Across the Web
reactjs - Material UI Select - object as value fails - Stack Overflow
I created a Select dropdown in order to change the displayed values. So when I change the selection, the data on the page...
Read more >React Select component - Material UI - MUI
Select components are used for collecting user provided information from a list of options.
Read more >How to create a material dropdown selection in Reactjs using ...
The value property defines which one to mark selected. If you click on any of these items, it will not change the selection....
Read more >Use JavaScript Objects In Material UI Select ... - YouTube
... it does not directly support setting up objects in the ui select ... In Material UI Select Component Using React (Set Default...
Read more >API - React Select
Indicate if the value entered in the field is invalid * ... If you wish to overwrite a component, pass in an object...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Faced with the same issue. The only problem is TS checks, but if I use “ts-ignore” everything works:
I just did <MenuItem value={
${JSON.stringify(complexObject)}
}/>