按钮中的选定属性更改(反应)

时间:2018-10-04 21:44:02

标签: reactjs

我的组件在Selected中具有属性<ListItem Button/> 好的,但是我更改了此菜单,并且希望在选择菜单时选择另一个元素。如何将状态更改转移到组件? (我正在学习react.js)

import React, { Fragment, Component } from 'react';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';
import ListItem from '@material-ui/core/ListItem';
import List from '@material-ui/core/List';
import Divider from '@material-ui/core/Divider';
import { Home, Payment, Settings } from '@material-ui/icons/';

export default class Navigation extends Component {
  state = {};

  render() {
    return (
      <Fragment>
        <Divider />
        <List component="nav">
          <ListItem button selected>
            <ListItemIcon>
              <Home />
            </ListItemIcon>
            <ListItemText primary="Strona główna" />
          </ListItem>
          <ListItem button>
            <ListItemIcon>
              <Payment />
            </ListItemIcon>
            <ListItemText primary="Moje płatności" />
          </ListItem>
        </List>
        <Divider />
        <List component="nav">
          <ListItem button>
            <ListItemIcon>
              <Settings />
            </ListItemIcon>
            <ListItemText primary="Ustawienia" />
          </ListItem>
        </List>
      </Fragment>
    );
  }
}

0 个答案:

没有答案