配列をオブジェクトにする

2022/06/06に公開

1行のインプットフォームを2行にしたい


-  const [memoList,setMemoList] = useState(['aa', 'bb', 'cc', 'dd']);

+ export type Memo = {
+  title: string
+  body: string
+ }

+  const [memoList,setMemoList] = useState<Memo[]>([{
+    title:'',
+    body:'',
+ }]);

  const onClickAdd = () => {
    if (inputText === '')return;
-   const newTasks = [...memoList, inputText];
+   const newTasks = [...memoList, { title: inputText, body: inputText }];
    setMemoList(newTasks);
    setInputText('');
  };

完成形

Discussion