State Management 5.13_Categories


Categories


ボタンを使用してtodoのカテゴリを変更できる機能を追加しましょう


onClickへ

ToDo.tsx

import React from "react";
import { useSetRecoilState } from "recoil";
import { IToDo, toDoState } from "../../../atoms";

export default function ToDo({ text, category, id }: IToDo) {
    const setToDos = useSetRecoilState(toDoState);
    const onClick = (event: React.MouseEvent<HTMLButtonElement>) => {
        const {
            currentTarget: { name },
        } = event;
    };
    return (
        <li>
            <span> {text}</span>
            {category !== "DOING" && (
                <button name="DOING" onClick={onClick}>
                    Doing
                </button>
            )}
            {category !== "TO_DO" && (
                <button name="TO_DO" onClick={onClick}>
                    To Do
                </button>
            )}
            {category !== "DONE" && (
                <button name="DONE" onClick={onClick}>
                    Done
                </button>
            )}

            {/* {category !== "DOING" && <button onClick={() => onClick("DOING")}>Doing</button>}
            {category !== "TO_DO" && <button onClick={() => onClick("TO_DO")}>To Do</button>}
            {category !== "DONE" && <button onClick={() => onClick("DONE")}>Done</button>} */}
        </li>
    );
}