Cleaned up, extracted List to a component
This commit is contained in:
parent
423dadec0b
commit
76fb43b9d6
File diff suppressed because one or more lines are too long
@ -2,7 +2,7 @@ import "./App.css";
|
||||
import Playground from "./components/Playground";
|
||||
import Logo from "./components/Logo";
|
||||
import Workplace from "./components/Workplace";
|
||||
|
||||
// <Playground title="👨🏻💻" />
|
||||
function App() {
|
||||
return (
|
||||
<>
|
||||
@ -11,7 +11,7 @@ function App() {
|
||||
<Logo />
|
||||
</header>
|
||||
<h1>Guillotine-cutter App</h1>
|
||||
<Playground title="👨🏻💻" />
|
||||
|
||||
<Workplace />
|
||||
</div>
|
||||
</>
|
||||
|
10
src/components/List.js
Normal file
10
src/components/List.js
Normal file
@ -0,0 +1,10 @@
|
||||
export default function List(props) {
|
||||
const rectangles = props.rectangles;
|
||||
const listItems = rectangles.map((rectangle) => (
|
||||
<li>
|
||||
{rectangle.w} x {rectangle.h}
|
||||
</li>
|
||||
));
|
||||
|
||||
return <> {listItems}</>;
|
||||
}
|
@ -1,18 +1,24 @@
|
||||
import { useState } from "react";
|
||||
import List from "./List";
|
||||
|
||||
export default function Workplace() {
|
||||
let figurki = [{ w: "100px", h: "100px", c: "red" }];
|
||||
const [width, setWidth] = useState("");
|
||||
const [height, setHeight] = useState("");
|
||||
const [rectangleArray, setRectangleArray] = useState("");
|
||||
|
||||
const handleSubmit = (evt) => {
|
||||
evt.preventDefault();
|
||||
figurki.push({ w: width + "px", h: height + "px", c: "blue" });
|
||||
console.log(figurki);
|
||||
const numbers = [{ w: "100px", h: "100px", c: "red" }];
|
||||
numbers.push({ w: "200px", h: "300px", c: "cyan" });
|
||||
|
||||
const handleFormSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
numbers.push({ w: width + "px", h: height + "px", c: "blue" });
|
||||
console.log(numbers);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<br />
|
||||
<form onSubmit={handleFormSubmit}>
|
||||
<label>
|
||||
Dimensions:
|
||||
<input
|
||||
@ -28,15 +34,7 @@ export default function Workplace() {
|
||||
</label>
|
||||
<input type="submit" value="Submit" />
|
||||
</form>
|
||||
<ul>
|
||||
{figurki.map((figurka, index) => {
|
||||
return (
|
||||
<li key={index}>
|
||||
{figurka.w} x {figurka.h}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
<List rectangles={rectangles} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user