“UseEffect Async menunggu” Kode Jawaban

cara menggunakan async menunggu di dalam evefeffect

useEffect(() => {
    async function fetchData() {
        try {
            const response = await fetch(
                `https://www.reddit.com/r/${subreddit}.json`
            );
            const json = await response.json();
            setPosts(json.data.children.map(it => it.data));
        } catch (e) {
            console.error(e);
        }
    };
    fetchData();
}, []);
Red Team

async di EFFEFFECT

  useEffect(() => {
    (async () => {
      const products = await api.index()
      setFilteredProducts(products)
      setProducts(products)
    })()
  }, [])

Runtime Terror

UseEffect Async menunggu

const getUsers = async () => {
 const users = await axios.get('https://randomuser.me/api/?page=1&results=10&nat=us');
 setUsers(users.data.results);
};

useEffect(() => {
 getUsers();
}, []);
Clever Crane

bereaksi ovefect async javascript

const [users, setUsers] = useState([]);
  
useffect(() => {
  const getUsers = async () => {
    let response = await fetch('/users');
    let data = await response.json();
    setUsers(data);
  };
    
 getUsers();
}, []);
Julio Polycarpo

async di EFFEFFECT

function myApp() {
  const [data, setdata] = useState()

  useEffect(() => {
    async function fetchMyAPI() {
      const response = await fetch('api/data')
      response = await response.json()
      setdata(response)
    }

    fetchMyAPI()
  }, [])
}
Keerthan Chand

async useeffect

useEffect(() => {
  (async function anyNameFunction() {await loadContent();})();
}, []); 
Jittery Jaguar

Jawaban yang mirip dengan “UseEffect Async menunggu”

Pertanyaan yang mirip dengan “UseEffect Async menunggu”

Lebih banyak jawaban terkait untuk “UseEffect Async menunggu” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya