score:3
Accepted answer
Try this:
renderSelectDropdown() {
let list = [];
this.state.users.forEach((user, idx) =>
{
let opt = this.state.info.map((item) => {
this.state.info[user.name][item].map((s, key) => {
<option key={key}>{s}</option>;
})
});
list.push(<optgroup key={idx} label={user.title}>{opt}</optgroup>);
});
return list;
}
render() {
let list = renderSelectDropdown();
return (
<div>
<input type="text" name="name">
<select>
{list}
</select>
</div>
)
}
score:0
The react way is this simple
<div>
{this.state.users.map(user => {
return <p> {user.prop} </p>
})}
</div>
Source: stackoverflow.com
Related Query
- What is the correct approach in React to loop through an array to build html-select list of items in a function and call it in render()?
- What is the correct way to loop through this array of objects inside of render, react
- React JS: Loop through a multi-dimensional array and determine/load the correct component
- react loop through array of strings with delay and set the text value
- What is the correct way to add to an array with splice in react
- loop through multiple objects inside the first array from JSON data displaying two arrays with objects in React using FUNCTION COMPONENT
- What is the best approach to build a react app with a large amount of component pages?
- how can i loop through the array inside of an object. and render it in the react component
- React - Loop through an array of objects, and highlight the selected item onClick
- How to loop through an array and display data within the object of that array, in react and javascript
- Nothing is showing when I loop through the array using forEach in react
- Loop through an array in React with pause in between the iterations
- What is the correct way of adding a dependency to react in your package.json for a react component
- What is the correct order of execution of useEffect in React parent and child components?
- What is the correct type for React Click Event?
- what is the correct type for a React instance of a component in typescript
- What is the correct way to animate/transition between routes in react router
- What is the correct pattern in React JS to invoke a component method on specific props change?
- Loop through simple array of objects in React
- What is the correct way to change Navbar values in React based on if user is logged in?
- What is the correct way to define a React component's contextTypes in TypeScript?
- What is the correct typescript type for react children?
- Loop through an array to create routes in react router
- What is the simplest way of testing that a React Component contains a html node with enzyme?
- Is it possible to loop through an array to dynamically generate react components?
- What is the correct way to add additional middleware through a redux store enhancer?
- What is the correct pattern for utility function when using React hooks?
- Loop through array of file urls and download each one with React
- How to loop through properties of objects inside of an array within a React component?
- How to keep and loop the style of HTML element from an Array in REACT?
More Query from same tag
- Issues with installing surge
- How to change font color of unselected Chakra UI tabs?
- how to make a load of states maintainable in functional components in react?
- ReactJS - Updating the state causes lag
- React Router: Route with nested params not hit
- How to conditionally render ReactJS content based of user's Operation System
- Javascript + React :- Unable to put the data in table and then render it
- Is there any alternative to the used method 'scroll top' when a link is clicked?
- ReactJS incrementor++ not working inside useReducer
- React updating state in two input fields from form submission
- How do I use constants within typescript type definitions?
- ReactJs function call and instead saw an expression no-unused-expressions
- What is a concrete example of jest.fn() used to test a React component?
- How to remove side scroll?
- Merge Arrays into Object gives undefined
- Cannot sort array of objects in react
- How can i access and pass a variable value defined in return method and pass it to another component in reactjs?
- How to resolve Uncaught TypeError: Cannot read property 'body' of null for tinymce.4.2.7.min.js?
- onClick to call function from another JS file with react
- How can I store cookies on a local client that are returned from a local backend API?
- Third party API call through Firebase Cloud functions ( with Blaze plan). React/Redux
- Chat Box UI not scrolling with react-bootstrap Accordion
- React: Higher-Order Component: Solid useLDflex()
- Ant design: get Id from datepicker in onChange
- React: Good Practices For CDNs, Node_Modules and Both
- Html option and input field not displayed proper
- Track if a component is on or off screen
- Prevent rerendering casued by replacement between simple react components
- React render has the correct data but won't render the JSX
- Cannot display MAP from react-map-gl and Mapbox