Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How to get access to the PromiseResult in React when calling Azure Cosmos DB api

function App() {
    const [newMembers, setNewMembers] = useState([]); // initially set to an empty array

    useEffect(() => {
        dataFetch().then(members => setMembers(members));
    }, []); // providing an empty array means: run this effect only once when this component is created.

    // do something with the newMembers. Initially, it will be [] 
    // but as soon as the data is retrieved from the DB, the actual data will be 
    // in the state and the component will be rerendered.
}
 
PREVIOUS NEXT
Tagged: #How #access #PromiseResult #React #calling #Azure #Cosmos #DB #api
ADD COMMENT
Topic
Name
3+7 =