todo list frago88
์ ์ปดํฌ๋ํธ ๋ชจ๋๋ฅผ styled component
๋ก ๋ฐ๊ฟ์ฃผ์๋ค. ๊ทธ ํ ๊ธฐ์กด style.css ๋ฅผ ๋ชจ๋ ์ญ์ ํ์๋ค.
todo list frago88
๊ธฐ์กด useState ๋ฐฉ์์์ Redux ๋ก state ๊ด๋ฆฌ ๋ฐฉ๋ฒ์ ๋ฐ๊พธ์๋ค.
react-router-dom
๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก Router.js ์์ฑ, detail.js(์์ธํ์ด์ง)๋ฅผ ๋ง๋ ํ ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉํ์๋ค.
find() ๋ฉ์๋๋ ์ฃผ์ด์ง ํ๋ณ ํจ์๋ฅผ ๋ง์กฑํ๋ ์ฒซ ๋ฒ์งธ ์์์ ๊ฐ์ ๋ฐํํฉ๋๋ค. ๊ทธ๋ฐ ์์๊ฐ ์๋ค๋ฉด undefined๋ฅผ ๋ฐํํฉ๋๋ค.
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(element => element > 10);
console.log(found);
// expected output: 12
const inventory = [
{name: 'apples', quantity: 2},
{name: 'bananas', quantity: 0},
{name: 'cherries', quantity: 5}
];
const result = inventory.find(fruit => fruit.name === 'cherries');
console.log(result) // { name: 'cherries', quantity: 5 }
const Detail = () => {
const todos = useSelector((state) => state.inputTodo.todos);
const navigate = useNavigate();
const param = useParams();
const thisTodo = todos.find((e) => e.id === param.id)
// param์์ ๋ค์ด์จ id๊ฐ๊ณผ state ์ธ todos ์ id ๊ฐ์ด๋ ๊ฐ์ ๊ฐ์ฒด๋ฅผ ์ฐพ๋๋ค.
const shoutedId = param.id.split('-')[0]
return (
<Background>
<Modal>
<Top>
<div>id : {shoutedId}</div>
<div><button onClick={() => navigate('/')}>์ด์ ์ผ๋ก</button></div>
</Top>
<Bottom>
<h1>{thisTodo.title}</h1>
<div>{thisTodo.body}</div>
</Bottom>
</Modal>
</Background>
)
}