Lists
Lists
Lists are used to display data in an ordered format and mainly used to display menus on
websites. In React, Lists can be created in a similar way as we create lists in JavaScript.
Let us see how we transform Lists in regular JavaScript.
The map() function is used for traversing the lists. In the below example, the map()
function takes an array of numbers and multiply their values with 5. We assign the new
array returned by map() to the variable multiplyNums and log it.
Ex2:
const list = [
{
id: 'a',
firstname: 'Robin',
lastname: 'Wieruch',
year: 1988,
},
{
id: 'b',
firstname: 'Dave',
lastname: 'Davidds',
year: 1990,
},
];
Ex3:
const initialList = [
'Learn React',
'Learn Firebase',
'Learn GraphQL',
];
setValue('');
event.preventDefault();
};
return (
<div>
<ul>
{list.map(item => (
<li key={item}>{item}</li>
))}
</ul>
<form onSubmit={handleSubmit}>
<input type="text" value={value} onChange={handleChange} />
<button type="submit">Add Item</button>
</form>
</div>
);
};
export default ListWithAddItem;