I am new to React and was trying to list all the array numbers. From the tutorial what I have understood is functions are also components in react. I tried to create a function component and access that functional component in another component(PersonList) But while executing I got the below error.
ReferenceError: number is not defined[Learn More]
If I replace PersonList with NumberList, it works fine. Can you please let me know what is wrong with my code?
Working code =============
ReactDOM.render(
<NumberList />,
document.getElementById('root')
);
Not working code ================
class PersonList extends React.Component {
render() {
<div>
<NumberList/>
</div>
};
}
function NumberList() {
const numbers = [1, 2, 3, 4, 5];
const listItems = numbers.map((number) =>
<li>{number}</li>
);
return (
<ul>{listItems}</ul>
);
}
ReactDOM.render(
<PersonList />,
document.getElementById('root')
);