Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

render async function to component

import React, {useState, useEffect} from "react"

const ShowPosts = () => {
    const [posts, setPosts] = useState([]);
    
    useEffect( () => { 
        async function fetchData() {
            try {
                const res = await axios.get('/posts'); 
                setPosts(res.data);
            } catch (err) {
                console.log(err);
            }
        }
        fetchData();
    }, []);
    return <div>{posts}</div>
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: typescript random 
Typescript :: retrieve data from firebase flutter 
Typescript :: locking value of cell 
Typescript :: typescript hashmap 
Typescript :: how to get value from observable 
Typescript :: live airplane tracker 
Typescript :: footer credits with jquery date time 
Typescript :: react typescript create react app 
Typescript :: ganache web3 
Typescript :: print all objects linked list python 
Typescript :: typescript loop through dictionary 
Typescript :: plot multiple plots in r 
Typescript :: provider in ethers.js 
Typescript :: typescript import type 
Typescript :: counts of unique values in rows of given 2D array numpy 
Typescript :: typescript generic function 
Typescript :: typescript err type 
Typescript :: how to push value in empty array in typescript 
Typescript :: accessing formcontrol from fromgroup 
Typescript :: 2. Write a program to draw this. Assume the innermost square is 20 units per side, and each successive square is 20 units bigger, per side, than the one inside it. 
Typescript :: nest js null exclude 
Typescript :: merge to datasets in r 
Typescript :: typescript array 
Typescript :: typeorm select join column querybuilder 
Typescript :: onSubmit for form in antd 
Typescript :: matlab components area 
Typescript :: show the current time realtime in vue 
Typescript :: disadvantages of automation 
Typescript :: onblur vs valuechange 
Typescript :: date formats in mongodb 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =