Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

useContext from localhost

import React,{useState, createContext} from 'react';

export const ProductsContext = createContext();

export const ProductsProvider = props => {
    const [categories, setCategories] = useState({ categories: {} });
    const [products, setProducts] = useState({ products: {} });
    const [loading, setLoading] = useState(true);
    useEffect(() => {
        (async () => {
            const [categoriesResult, productsResult] = await Promise.all([fetch('http://localhost:3000/api/categories'), fetch('http://localhost:3000/api/products')]);
            setCategories(categoriesResult);
            setProducts(productsResult);
            setLoading(false);
          })();
        }, []);
    return (
    <ProductsContext.Provider value={ { products, categories, loading } }>
        {props.children}
    </ProductsContext.Provider>
    );
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: create-react-app height issues with flex 
Javascript :: node.js how to install a custom version of packgage 
Javascript :: what is x path js 
Javascript :: Deputy json file 
Javascript :: how to add,delete,update property in javascript object 
Javascript :: set @Output through modalref angular 
Javascript :: java home sdk error 
Javascript :: trie node pseudocode 
Javascript :: Subscription field must return Async Iterable. Received: undefined. 
Javascript :: declarar function javascript 
Javascript :: arrow function no argument object 
Javascript :: javascript YUP utilisation to math certain disire in forms 
Javascript :: babel 7 ReferenceError: regeneratorRuntime 
Javascript :: nodejs s3 read 
Javascript :: push code from vscode using CL 
Javascript :: pass data from parent to child component angular 8 
Javascript :: instant search initial value 
Javascript :: openai giving me a 401 
Javascript :: show more vs editor shortcut key 
Javascript :: how to show name of inactive also in react-navigation-material-bottom-tabs 
Javascript :: how to change div style to full page react 
Javascript :: tokenize javascript 
Javascript :: javascript test https 
Javascript :: decrypt javascript code 
Javascript :: &amp;&amp; in javascript new 
Javascript :: how-to get selected value of a dropdown menu in reactjs 
Javascript :: actual jquery 
Javascript :: react using props and parent state 
Javascript :: volta node list 
Javascript :: javascript one linde condition 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =