Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

await fetch in react

async function fetchFunction() {
  try{
	const response = await fetch(`http://url.com`);
	const json = await response.json();
  }
  catch(err) {
    throw err;
    console.log(err);
  }
}
Comment

fetch await reactjs

const [products, setProducts] = useState([]);

// Fetch array of products
async function initProducts() {
    await fetch('http://127.0.0.1:5000/listProducts')
        .then(response => response.json())
        .then(response => {
            setProducts(response.result);
            console.log(response.result);
        )
        .catch(err => console.error(err));
}

// Get products to html with map function
function getProductsHtml() {
    return products.map(product =>
        <h1>{product.ProductName}</h1>
        <h1>{product.ProductDescription}</h1>
    );
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript code 
Javascript :: jquery after 
Javascript :: add active class and remove active class by click 
Javascript :: javascript truncate decimal without rounding 
Javascript :: scrolltop in javascript 
Javascript :: set span text jquery 
Javascript :: link react router dom 
Javascript :: angular stoppropagatio 
Javascript :: how to remove minutes with moment js 
Javascript :: avoid no-param-reassign when setting a property 
Javascript :: how to make link in discord.js 
Javascript :: Reverse a String With Built-In Functions 
Javascript :: react string to integer 
Javascript :: remove char from string js 
Javascript :: validate password with 8 Characters, One Uppercase, One Lowercase, One Number and One Special Case Character 
Javascript :: format number with commas js 
Javascript :: check if item not in array node js 
Javascript :: get form data as object jquery 
Javascript :: jquery remove class 
Javascript :: why is my deleteOne mongoose middleware not working 
Javascript :: laravel json response with error code 
Javascript :: javascript canvas beziercurveto 
Javascript :: post xml with axios nodejs 
Javascript :: embed video by javascript 
Javascript :: set timeout 
Javascript :: json placholder 
Javascript :: fetch function javascript 
Javascript :: how to get the data from url in javascript 
Javascript :: javascript define global variable 
Javascript :: best and fastest encrypt and decrypt value in javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =