March 2019
Intermediate to advanced
534 pages
14h 52m
English
Let's say that you have an array of three objects that you need to display as a list on one of your screens. You can add this array to the state of your component, then map each array item to a ListItem component. Here's the code:
import React, { useState } from 'react';import List from '@material-ui/core/List';import ListItem from '@material-ui/core/ListItem';import ListItemText from '@material-ui/core/ListItemText';export default function UsingStatetoRenderListItems() { const [items, setItems] = useState([ { name: 'First Item', timestamp: new Date() }, { name: 'Second Item', timestamp: new Date() }, { name: 'Third Item', timestamp: new Date() } ]); return ( <List> {items.map((item, index) => ( <ListItem key={index} button ...Read now
Unlock full access