Web
React 분류

[React] material-ui 추가

작성자 정보

  • codls 작성
  • 작성일

본문

1. Material-UI 설치

npm install @material-ui/icons @mui/material @material-ui/core @mui/system
 
2. 컴포넌트 분리
images%2Fexoluse%2Fpost%2F1206bfc0-5c88-4856-aed5-aa9dd9dac6c9%2FScreen%20Shot%202021-09-18%20at%2012.53.59%20AM.png
 
1) Header.js (상단)

   
      import { AppBar, IconButton, Toolbar, Typography } from '@material-ui/core';
      import { Menu as MenuIcon } from "@material-ui/icons";
       
      function Header() {
      return (
      <AppBar position="static">
      <Toolbar variant="dense">
      <IconButton edge="start" color="inherit" aria-label="menu" sx={{ mr: 2 }}>
      <MenuIcon />
      </IconButton>
      <Typography variant="h6" color="inherit" component="div">exoluse-react</Typography>
      </Toolbar>
      </AppBar>
      )}
      export default Header;
      
    
   
 
2) Bottomjs (하단)

         import { Restore as RestoreIcon, Favorite as FavoriteIcon, LocationOn as LocationOnIcon } from "@material-ui/icons";
         import { Paper, BottomNavigation, BottomNavigationAction } from '@mui/material';
          
         function Bottom() {
         return (
         <Paper sx={{ position: 'fixed', bottom: 0, left: 0, right: 0 }} elevation={3}>
         <BottomNavigationshowLabelsonChange={(event, newValue) => { // setValue(newValue);}}>
         <BottomNavigationAction label="Recents" icon={<RestoreIcon />} />
         <BottomNavigationAction label="Favorites" icon={<FavoriteIcon />} />
         <BottomNavigationAction label="Nearby" icon={<LocationOnIcon />} />
         </BottomNavigation>
         </Paper>
         )}
         export default Bottom;
         
 
3) EmpList.js (목록)

         import {useEffect, useState} from 'react';import { Link, useHistory } from 'react-router-dom';
         import { Add as AddIcon } from "@material-ui/icons";
         import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Paper, Fab } from '@mui/material';import './App.css';
          
         function EmpList() {
         let history = useHistory();
         let [empList, changeEmpList] = useState([]);
         let [refreshComponent, changeRefreshComponent] = useState("");
          
         useEffect( ()=>{
         fetch("http://localhost:3001/getEmpList").then((response)=>{
         return response.json();}).then( (response)=>{changeEmpList(response.data);} )}, [ refreshComponent ] );
          
         return (<><TableContainer component={Paper}><Table aria-label="simple table"><TableHead><TableRow><TableCell align="center">Id</TableCell><TableCell align="center">Name</TableCell></TableRow></TableHead><TableBody>{empList.map((row) => (<TableRowkey={row.id}sx={{ '&:last-child td, &:last-child th': { border: 0 } }}><TableCell component="th" scope="row" align="center">{row.id}</TableCell><TableCell align="center"><Link to={ '/detail/'+row.id }>{row.name}</Link></TableCell></TableRow>))}</TableBody></Table></TableContainer><Link to={ '/insert'}><Fab sx={{ position: 'fixed', bottom: 70, right: 10 }} color="primary" aria-label="add"><AddIcon /></Fab></Link></>)}
          
         export default EmpList;
         
 
 
images%2Fexoluse%2Fpost%2Fde54fc08-ec6b-4c79-803f-6f171d4e46f7%2FScreen%20Shot%202021-09-18%20at%2012.50.32%20AM.png
 

관련자료

댓글 0
등록된 댓글이 없습니다.
React 4 / 1 페이지
RSS
  • React 유튜브 채널 추천
    등록자 코드워리어
    등록일 01.09 조회 2195

    React React는 웹 개발에서 매우 인기 있는 라이브러리로, 학습을 위해 다양한 자료들이 필요합니다. React를 학습하고 싶은 분들을 위한 유튜버 …

  • 리액트의 개념과 장점, 컴포넌트
    등록자 루나테크
    등록일 12.29 조회 2507

    React 리액트(React)는 페이스북에서 개발한 사용자 인터페이스(UI)를 구축하기 위한 자바스크립트 라이브러리로, 단일 페이지 애플리케이션(SPA)을…

  • React 프로젝트 시작하기: 기본 단계부터 따라가기
    등록자 루나테크
    등록일 12.29 조회 2196

    React 안녕하세요! React 프로젝트를 시작하는 기초적인 단계부터 천천히 살펴보려고 합니다. React는 사용자 인터페이스를 구축하기 위한 강력하고 …

  • [React] material-ui 추가
    등록자 codls
    등록일 09.04 조회 6018

    React 1. Material-UI 설치 npm install @material-ui/icons @mui/material @material-ui/core…