I want to write a simple program where using for loop it will print numbers from 0 to 10. I am trying to use a for loop which will print numbers from 0 to 10 and will pass the props to child component. Here is my code:
import React, { Component } from 'react';
class App extends Component {
render() {
return(
{
for(var i=0;i<11;i++)
{
// var data=i;
}
}
);
}
}
const Print=(props)=>{
return(
{props.value}
);
}
export default App;
Answer
You can push the JSX to an array and render that.
class App extends React.Component {
render() {
const result = [];
for (var i = 0; i < 11; i++) {
result.push( );
}
return {result};
}
}
const Print = props => {
return {props.value};
};
ReactDOM.render( , document.getElementById("root"));
No comments:
Post a Comment