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 :: extract number from string 
Javascript :: settimeout 
Javascript :: regex pattern to validate email 
Javascript :: run react app in react 18 
Javascript :: javascript load multiple images 
Javascript :: check box all in jequery data table 
Javascript :: (node:2496) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead. 
Javascript :: jquery open image in new tab 
Javascript :: react native android run 
Javascript :: ajax authorization header token 
Javascript :: node js split data 
Javascript :: have flat list automatically wrap react native 
Javascript :: jquery remove disabled property from button 
Javascript :: are you sure you want to proceed click ok button javascript code 
Javascript :: javascript is JSON string valid 
Javascript :: make image circle css react 
Javascript :: selecionar valselect2 js 
Javascript :: discord.js random message 
Javascript :: node js get input from console 
Javascript :: s3 list objects in folder node js 
Javascript :: check if a variable is a number in javascript 
Javascript :: hide label chratjs 
Javascript :: copy localstorage javascript 
Javascript :: read from s3 bucket nodejs 
Javascript :: create path if not exist node js 
Javascript :: js window width change 
Javascript :: jquery validate conditional 
Javascript :: js check if element hidden 
Javascript :: eslint unexpected console statement 
Javascript :: how to wait until a variable is set javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =