목록2025/03/17 (2)
코드네임 :
import { useState, useEffect } from "react";function App() { const [loading, setLoading] = useState(true); const [coins, setCoins] = useState([]); useEffect(() => { fetch("https://api.coinpaprika.com/v1/tickers") .then((response) => response.json()) .then((json) => { setCoins(json); setLoading(false); }); }, []); return ( div> h1>The Coins! {loading ? "" : `(${coins.length})`}h1> {loading ? stro..
import { useState, useEffect } from "react";function App() { const [toDo, setToDo] = useState(""); const [toDos, setToDos] = useState([]); const onChange = (event) => setToDo(event.target.value); const onSubmit = (event) => { event.preventDefault(); if (toDo === "") { return; } // 중요!!!! state를 절대 직접 수정하지 않고, 함수로 수정 // 그러니 toDo ="";는 절대 안되고 아래처럼 setToDos((currentArray) => [toDo, ...currentArray]..