score:6
{...items}
is passed as childrens in DropdownMenu.js
.
Its available as a this.props.children
this.props.children
can be array or object depend on how you rendering the children elements.
in your case
<DropdownMenu
label={'Some label'}
onChange={() => {}}
>
{...items}
</DropdownMenu>
items is an array. As we know
array is also type of object in javascript
with key equal to element's index and value is element itself
{...items}
: this will passed as a object with key as a element index and value equal to array element.
To fix your problem, you should passed it without using spread operator.
{items}
: this will passed as an array.
<DropdownMenu
label={'Some label'}
onChange={() => {}}
>
{items}
</DropdownMenu>
score:7
Its not because of map that you get children as object, but because you use spread operator for the items in
<DropdownMenu
label={'Some label'}
onChange={() => {}}
>
{...items} {/*spread operator here */}
</DropdownMenu>
Now that after map items is an array using {...items }
makes it an object since you wrap your result of spread operator with {}
, If you write {items}
, that will be fine
<DropdownMenu
label={'Some label'}
onChange={() => {}}
>
{items}
</DropdownMenu>
Source: stackoverflow.com
Related Query
- React.js - this.props.children an object when spreading the result of a .map from the parent
- Props object what is the meaning of passing children to the component from React official documentation
- Accessing React component children props from the parent
- Error when creating new object from existing one using `...`: In this environment the sources for assign MUST be an object
- Passing props from react router to children on the server
- React what's the right way to get a parent props from its children
- Fixing typescript warnings when inferring react props types from map of string=>type
- Why is there a semi-colon in the object structure for expected props in this typescript react component?
- Mirroring the position when moving objects from the array to the array to another object in React
- How to correctly type a null value in typescript react app, retrieved from an JSON object (api call) when using Object.entries to retrieve the value?
- How to fix "Uncaught Error: Objects are not valid as a React child" when passing objects, obtained from the blockchain, to the children components
- Event object from onClick event couldn't access one of the props on the element in react
- React Redux: Reload the component from ACTION when the props change
- What causes the failure to pass props from parent to child in this React application?
- React setState returning empty result from server, when the result gets received successfully
- Unable to update a list with react when its value is being changed using the hook useState function from React TypeError: map is not a function
- What is the best way to define "KEY" in React when creating a list with map function from an array which containing no unique ID or fields?
- How should the react component re-render itself when props from redux have been updated?
- React Not returning Child from map loop when creating SVG from JSON object
- Where can I find the API guide for this usage of passing props to children in React
- How do I pass an object (created by a buttonClick event) from child to parent in react when already using props for a styled button
- TypeError: Cannot read property 'map' of undefined is showing when I'm trying to map over the props passed from parent component to child component
- React + Redux - Input onChange is very slow when typing in when the input have a value from the state
- React changing props on grandchildren: object is not extensible / tree traversing react children
- How to initialize the react functional component state from props
- How to pass the match when using render in Route component from react router (v4)
- Does passing an object via props to child react component, clone the original object or pass by reference?
- React context is undefined when the children are rendered using this.props.children
- CDN links for React packages and how to import it when using react using the scripts from CDN
- Why does React re-render children when the parent changes?
More Query from same tag
- How do I mock a async function in a component when testing reactjs with enzyme and jest?
- Dealing With Multiple Flatlists on the same Screen
- How to call a function and then navigate to a route when click on a button?
- Mapping two table ,React or Sql?and how?
- Redux updating nested data [Immutable Update Patterns]
- React Accordion Update height when child DOM has new Table to render
- i want to change the selected values and also update with using select and option with using react js
- (Gatsby) How to pass image source as a prop in MDX component
- Change in Context doesn't show in Consumer element
- Why can't I send prop as an object property in React component (typescript)?
- How to type Actions for Redux-Observable's Epics with TypeScript
- Overcoming lack of refs in stateless components
- I have to click on my link twice before state is update and styling is changed
- Spring Boot 2.1.0 only serve index.html if resource not resolved (SPA, react-router)
- How Can I Change Next.Js Image Component src with animation?
- How to use react-form-stepper in reactjs
- How add style for child elements with react-jss component?
- Adding a JSON file into my table using a button
- Firebase 3.0 throws cross-origin error when bundled with webpack
- TypeScript 3: JSX element type 'Component' does not have any construct or call signatures. [2604]
- Having trouble dialing in a filter if statement - multiple dropdowns
- Get data from server before component render in ReactJs
- "How to update value of item initialized from getDerivedStateFromProps on some action"?
- Couldn't find a `pages` directory. Please create one under the project root
- I can't consume a JSON file
- In ReactJS, facing problem in rendering the data from an API due to its odd structure
- Argument of type 'unknown' is not assignable to parameter of type
- React MUI [FilledInput] doesn't capture last the character
- How to show validation error in form in react js?
- Calling a function on React Element before the Component did mount