onInsert 함수를 만든 뒤에는 해당 함수를 TodoInsert 컴포넌트의 props로 설정해 주세요.

    App.js

    import React, { useState, useRef, useCallback } from 'react';
    import TodoTemplate from './components/TodoTemplate';
    import TodoInsert from './components/TodoInsert';
    import TodoList from './components/TodoList';
     
    const App = () => {
      const [todos, setTodos] = useState([
        {
          id: 1,
          text: '리액트의 기초 알아보기',
          checked: true,
        },
        {
          id: 2,
          text: '컴포넌트 스타일링해 보기',
          checked: true,
        },
        {
          id: 3,
          text: '일정 관리  만들어 보기',
          checked: false,
        },
      ]);
     
      // 고윳값으로 사용될 id
      // ref 사용하여 변수 담기
      const nextId = useRef(4);
     
      const onInsert = useCallback(
        text => {
          const todo = {
            id: nextId.current,
            text,
            checked: false,
          };
          setTodos(todos.concat(todo));
          nextId.current += 1; // nextId 1 더하기
        },
        [todos],
      );
     
      return (
        <TodoTemplate>
          <TodoInsert onInsert={onInsert} />
          <TodoList todos={todos} />
        </TodoTemplate>
      );
    };
     
    export default App;

    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.