I want to show a dynamic select, with values between 1 and 100 in a react component.
In Angular 2 is
<select> <option *ngFor="let i of numbers">{{i}}</option> </select> <!--numbers is an array [1,2,3,4,...100]-->
How is this in React?
We often need to render an array in the UI. Angular does this by using *ngFor — an HTML construct. React does this by using map() — a JS method. That's about it for rendering arrays in Angular and React.
Angular is mostly used to build complex enterprise-grade apps like single-page apps and progressive web apps, while React is used to build UI components in any app with frequently variable data. Angular's learning curve is steeper due to its too many in-built functionalities while React's smaller package size.
The supported version of React is 15.3. 2. Server-side rendering is not supported. To be able to use the GoodData React Components in your Angular 2+ environment, wrap each component into an Angular component, and then render the React component using ReactDom.
View is the most common element in React Native. You can consider it as an equivalent of the div element used in web development.
You can use map
on numbers and create the options dynamically like this:
<select> { numbers.map(el => <option value={el} key={el}> {el} </option>) } </select>
Check this example:
var numbers = [...Array(100).keys()]; var App = () => { return( <select> { numbers.map(el => <option value={el} key={el}> {el} </option>) } </select> ) } ReactDOM.render(<App/>, document.getElementById('app'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> <div id='app'/>
RepeatModule
is the equivalent in Reactjs
ReactDOM.render(<RepeatModule items={items} />, document.getElementById('react-content'));
LIVE DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With