npm install @mui/material @emotion/react @emotion/styled
import { Container } from "@mui/material";
return (
<Container>
<Counter></Counter>
</Container>
);
}```
import Grid from "@mui/material/Grid";
function App() {
return (
<Container>
<Grid container>
<Counter></Counter>
<Counter></Counter>
<Counter></Counter>
<Counter></Counter>
<Counter></Counter>
<Counter></Counter>
</Grid>
</Container>
);
}```
function App() {
return (
<Container>
<Grid container spacing={1}>
<Grid item xs={12} sm={6} md={4}>
<Counter></Counter>
</Grid>
<Grid item xs={12} sm={6} md={4}>
<Counter></Counter>
</Grid>
<Grid item xs={12} sm={6} md={4}>
<Counter></Counter>
</Grid>
</Grid>
</Container>
);
}
function Counter2() {
const [open, setOpen] = useState(false);
return (
<div style={{ border: "10px solid black", padding: 20 }}>
<h1>Counter - Dialog</h1>
<Button
variant="contained"
onClick={() => {
setOpen(true);
}}
>
Run
</Button>
<div style={{ display: open ? "block" : "none" }}>
<h2>Dialog Counter</h2>
<button>+</button> 0
<Button
variant="contained"
onClick={() => {
setOpen(false);
}}
>
close
</Button>
</div>
</div>
);
}
import Dialog from "@mui/material/Dialog";
...
function Counter2() {
const [open, setOpen] = useState(false);
return (
<div style={{ border: "10px solid black", padding: 20 }}>
<h1>Counter - Dialog</h1>
<Button
variant="contained"
onClick={() => {
setOpen(true);
}}
>
Run
</Button>
<Dialog open={open}>// 여기 바꿔줌!!
<h2>Dialog Counter</h2>
<button>+</button> 0
<Button
variant="contained"
onClick={() => {
setOpen(false);
}}
>
close
</Button>
</Dialog>
</div>
);
}
import Dialog from "@mui/material/Dialog";
import DialogTitle from "@mui/material/DialogTitle";
import DialogContent from "@mui/material/DialogContent";
import DialogActions from "@mui/material/DialogActions";
...
function Counter2() {
const [open, setOpen] = useState(false);
return (
<div style={{ border: "10px solid black", padding: 20 }}>
<h1>Counter - Dialog</h1>
<Button
variant="contained"
onClick={() => {
setOpen(true);
}}
>
Run
</Button>
<Dialog
open={open}
onClose={() => {
setOpen(false);
}}
>
<DialogTitle>Dialog Title</DialogTitle>
<DialogContent>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit.</p>
<button>+</button> 0
</DialogContent>
<DialogActions>
<Button
variant="contained"
onClick={() => {
setOpen(false);
}}
>
close
</Button>
</DialogActions>
</Dialog>
</div>
);
}
function getRandomColor() {
const letters = "0123456789ABCDEF";
let color = "#";
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
<div style={{ border: "10px solid" + getRandomColor(), margin: "20px 0" }}>
...
</div>
npx json-server --port 9999 --watch db.json
fetch('http://localhost:9999/counter')
.then((resp)=>resp.json())
.then((result)=>{
console.log(result.value);
})
useEffect(() => {
fetch("http://localhost:9999/counter")
.then((resp) => resp.json())
.then((result) => {
console.log(result);
setCount(result.value);
});
}, []);
fetch("http://localhost:9999/counter", {
method: "PATCH",
body: JSON.stringify({ value: count + 1 }),
headers: {
"Content-Type": "application/json",
},
})
.then((resp) => resp.json())
.then((result) => {setCount(result.value)});
출처 : 엘리스 아카데미