[TIL/React] 2023/04/24
src/App.js src/components/InputSection.js src/components/TodoSection.js src/components/CompleteSection.js현재까지의 스타일링 (styled-components)내일은 DeepDive를 읽
src/App.js
import React, { useState } from "react";
import InputSection from "./components/InputSection";
import TodoSection from "./components/TodoSection";
import CompleteSection from "./components/CompleteSection";
import styled from "styled-components";
import { createGlobalStyle } from "styled-components";
const GlobalStyle = createGlobalStyle`
body {
background: #d0e3ed;
opacity: 0.9;
}
`;
const inputArray = ["title", "subTitle", "desc"];
function App() {
const [inputValue, setInputValue] = useState({
title: "",
subTitle: "",
desc: "",
isDone: false,
});
const [editValue, setEditValue] = useState({
title: "",
subTitle: "",
desc: "",
isDone: false,
});
const [todos, setTodos] = useState([]);
const [id, setId] = useState("");
const noCompleteArray = todos.filter((todo) => todo?.isDone === false);
const completeArray = todos.filter((todo) => todo?.isDone === true);
const handleInputValue = (event) => {
const { value, name } = event?.target;
setInputValue((prev) => {
return { ...prev, [name]: value };
});
};
const handleEditValue = (event) => {
const { value, name } = event?.target;
setEditValue((prev) => {
return { ...prev, [name]: value };
});
};
const addButtonClick = () => {
setTodos((prev) => {
return [
...prev,
{
...inputValue,
id: `${inputValue?.title} ${inputValue?.subTitle} ${inputValue?.desc}`,
},
];
});
setInputValue({ title: "", subTitle: "", desc: "", isDone: false });
};
const deleteButtonClick = (id) => {
setTodos((prev) => {
return prev?.filter((todo) => todo?.id !== id);
});
};
const completeButtonClick = (id) => {
let newArray = todos?.map((todo) =>
todo?.id === id ? { ...todo, isDone: true } : todo
);
setTodos(newArray);
};
const editButtonClick = (id) => {
setId(id);
const editTodo = todos.find((todo) => todo?.id === id);
setEditValue(editTodo);
};
const saveButtonClick = (id) => {
setTodos((prev) => {
return [...prev]?.map((todo) => (todo?.id === id ? editValue : todo));
});
setId("");
setEditValue({
title: "",
subTitle: "",
desc: "",
isDone: false,
});
};
const cancelButtonClick = (id) => {
setId("");
setEditValue({
title: "",
subTitle: "",
desc: "",
isDone: false,
});
};
// console.log({ inputValue });
console.log({ todos });
return (
<div>
<GlobalStyle />
<InputSection
inputArray={inputArray}
inputValue={inputValue}
handleInputValue={handleInputValue}
addButtonClick={addButtonClick}
/>
<TodoSection
noCompleteArray={noCompleteArray}
editButtonClick={editButtonClick}
completeButtonClick={completeButtonClick}
inputArray={inputArray}
editValue={editValue}
handleEditValue={handleEditValue}
saveButtonClick={saveButtonClick}
editId={id}
cancelButtonClick={cancelButtonClick}
deleteButtonClick={deleteButtonClick}
/>
<CompleteSection
completeArray={completeArray}
deleteButtonClick={deleteButtonClick}
/>
</div>
);
}
export default App;
src/components/InputSection.js
``` import React from "react"; import styled from "styled-components";
const InputBorder = styled.div` margin: 40px; border: 1px solid skyblue; border-radius: 20px; padding: 10px; background-color: white; `;
const InputTitle = styled.h1` text-align: center; `; const InputMain = styled.div` display: flex; flex-direction: column; `; const InputTodo = styled.div` display: flex; justify-content: center; margin-bottom: 3px; `; const ButtonWrap = styled.div` text-align: center; `; const AddButton = styled.button` background-color: skyblue; color: white; border-radius: 5px; border: none; cursor: pointer; &:hover { background-color: dodgerblue; } `; const InputInput = styled.input` border-radius: 3px; padding: 4px; width: 200px; `;
const InputSection = ({ inputArray, inputValue, handleInputValue, addButtonClick, }) => { return (
export default InputSection;
> **src/components/TodoSection.js**
import React from "react"; import styled from "styled-components"; const TodoTitle = styled.h2` text-align: center; `;
const TodoSection = ({ noCompleteArray, editButtonClick, completeButtonClick, inputArray, editValue, handleEditValue, saveButtonClick, editId, cancelButtonClick, deleteButtonClick, }) => { return (
Title: {todo?.title}
SubTitle: {todo?.subTitle}
Desc: {todo?.desc}
export default TodoSection;
> **src/components/CompleteSection.js**
import React from "react"; import styled from "styled-components";
const CompleteTitle = styled.h2` text-align: center; `;
const CompleteSection = ({ completeArray, deleteButtonClick }) => { return (
Title: {todo?.title}
SubTitle: {todo?.subTitle}
Desc: {todo?.desc}
export default CompleteSection;
More to read
AI&ML 기초
Reference: https://bettermesol.github.io/ml/2019/09/16/ai-ml-dl/AI: 기계가 사람처럼 생각하고 판단하게 만드는 가장 넓은 범주의 기술입니다.ML: 데이터를 학습하여 스스로 규칙을 찾아내는 AI의 한 분야로,
'AI Agent Economy'Novitas : AI Agent가 지갑을 가지는 세상
얼마 전, 미래에셋증권 리서치 리포트(올해는 이더리움이다: 에이전트 시대의 Near Automata)를 접하게 되었습니다. AI Agent를 인간과 함께할 경제 주체로 바라보는 시각에 적잖이 충격을 받았더랬죠.한 가지 짚고 넘어갈 부분이 있습니다. 우리가 흔히 'AI'
'ERC-8004'Novitas: AI 에이전트 경제 주체
Web 4.0을 한 문장으로 정의하면 Sovereign Transact입니다.AI가 인간의 허락 없이 지갑을 소유하고, 결제를 수행하며, 인프라를 통제하는 주권적 경제 주체가 되는 세계입니다. Web 3.0이 블록체인 기반의 탈중앙화를 실현했다면, Web 4.0은 그