230510 - ๊ฐ„๋‹จํ•œ todoList

๋ฐฑ์Šน์—ฐยท2023๋…„ 5์›” 10์ผ
1

๐Ÿšฉ ๋กœ์ปฌ์— ๋ฆฌ์•กํŠธ ์„ค์น˜ํ•˜๋Š” ๋ฐฉ๋ฒ•

yarn์œผ๋กœ ์„ค์น˜ ๊ถŒ์žฅ!

-> npm๋ณด๋‹ค ์šฉ๋Ÿ‰์ด ํ›จ์”ฌ ์ ์Œ

https://yarnpkg.com/
$ npm install -g yarn
-> ์˜ˆ์ „ ๋ฒ„์ „์œผ๋กœ ์„ค์น˜๋จ (1.22.19)

$ corepack prepare yarn@stable --activate
-> ์ตœ์‹ ๋ฒ„์ „์œผ๋กœ ์—…๋ฐ์ดํŠธ ํ•˜๋Š” ๋ฒ•

yarn startํ•œ ํ›„ js ํŒŒ์ผ ์ˆ˜์ • ์‹œ ์˜ค๋ฅ˜ ๋ฐœ์ƒ

Failed to load config "react-app" to extend from.

-> ํ•™์›๋ถ„์ด ์•Œ๋ ค์ฃผ์‹  ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

  • ์˜์กด์„ฑ ์ฃผ์ž… : $ yarn add eslint-config-react-app --dev
  • eslint ๋ฒ„์ „ ์—…๋ฐ์ดํŠธ : $ eslint-config-react-app@latest --dev

react์—์„œ sass/scss ์‚ฌ์šฉํ•  ๋•Œ ์„ค์น˜๋ฐฉ๋ฒ•

$ yarn add sass

npm์œผ๋กœ react ์„ค์น˜ ๋ฐฉ๋ฒ•

React app
https://create-react-app.dev/
$ npm create react-app ํด๋”๋ช…
$ npm start






๐Ÿšฉ todoList

๋ฆฌ์•กํŠธ๋กœ ์•„์ฃผ ๊ฐ„๋‹จํ•˜๊ฒŒ ํˆฌ๋‘๋ฆฌ์ŠคํŠธ ๋งŒ๋“ค๊ธฐ

๐Ÿ“ ์„ค๋ช…

  • ๋‹ค๋ฅธ ๊ธฐ๋Šฅ ์ œ์™ธํ•˜๊ณ  ์ถ”๊ฐ€ ๊ธฐ๋Šฅ๋งŒ ๊ตฌํ˜„


โœ’๏ธ ์‚ฌ์šฉ๋ฒ•

์ž…๋ ฅ

App.js

import React, { useState } from "react";
import "./App.css";
import TodoBoard from "./components/TodoBoard";

function App() {
  const [inputValue, setInputValue] = useState("");
  const [todoList, setTodoList] = useState([]); // ์ž…๋ ฅํ•œ ์•„์ดํ…œ์„ ๋ชจ์•„์ค„ ๋ฐฐ์—ด

  const addItem = () => {
    console.log("inputValue๋Š”? : ", inputValue);
    setTodoList([...todoList, inputValue]); // ๊ธฐ์กด array์— ์ž…๋ ฅ๋œ inputValue๋ฅผ ์ถ”๊ฐ€. spread ์ด์šฉํ•˜์—ฌ ์ „์ฒด๋ฅผ ๊ฐ€์ ธ์˜ด.
    console.log("todoList๋Š”? : ", todoList);

    setInputValue(""); // input ์ดˆ๊ธฐํ™”
  };

  return (
    <div className="App">
      <input
        className="input-style"
        type="text"
        placeholder="ํ•  ์ผ์„ ์ž…๋ ฅํ•˜์„ธ์š”"
        onChange={(event) => setInputValue(event.target.value)}
        value={inputValue} // input ์ดˆ๊ธฐํ™”
      />
      <button className="btn-style" onClick={addItem}>์ถ”๊ฐ€</button>

      {/* todoList๋ฅผ(array๋ฅผ) props๋กœ TodoBoard์— ์ „๋‹ฌ. ๋Œ€๋ถ€๋ถ„ props์ด๋ฆ„๊ณผ("=" ์•ž๋ถ€๋ถ„) ์ „๋‹ฌํ•  ๋ณ€์ˆ˜/ํ•จ์ˆ˜๋ช…์˜ ์ด๋ฆ„์„ ๊ฐ™๊ฒŒ ํ•จ */}
      <TodoBoard todoList={todoList} />
    </div>
  );
}

export default App;

TodoBoard.jsx

import React from "react";
import TodoItem from "./TodoItem";

// props๋กœ ๋ช‡ ๊ฐœ๋ฅผ ๋ฐ›์•„์˜ฌ์ง€ ๋ชจ๋ฅด๊ธฐ ๋•Œ๋ฌธ์— map ์‚ฌ์šฉ
export default function TodoBoard(props) {
  return (
    <div>
      <h1>Todo List</h1>
      {props.todoList.map((item) => (
        // ๋ฐ›์•„์˜จ item์„ ๊ฐ๊ฐ์˜ TodoItem์— ์ „๋‹ฌ
        <TodoItem item={item} />
      ))}
    </div>
  );
}

TodoItem.jsx

import React from "react";

const TodoItem = (props) => {
  console.log("props๋Š”? : ", props);
  return (
    <div className="item">{props.item}</div> // ๋ฐ›์•„์˜จ ์ด๋ฆ„์ด item
  );
};

export default TodoItem;

์ถœ๋ ฅ

  • ์ด๋ฏธ์ง€๋กœ ๋Œ€์ฒด


๐Ÿ”— ์ฐธ๊ณ  ๋งํฌ & ๋„์›€์ด ๋˜๋Š” ๋งํฌ






profile
๊ณต๋ถ€ํ•˜๋Š” ๋ฒจ๋กœ๊ทธ

0๊ฐœ์˜ ๋Œ“๊ธ€