score:1
Accepted answer
i think adding a return into your getprojects()
service will solve your issue.
import {
stitch,
remotemongoclient,
anonymouscredential
} from "mongodb-stitch-browser-sdk";
export function getprojects() { //add async if you need to await in func body
const client = stitch.initializedefaultappclient("------");
const db = client
.getserviceclient(remotemongoclient.factory, "-----")
.db("----------"); // if these above are async, then await them as well.
// added return keyword here
return client.auth // should return promise to await in your component
.loginwithcredential(new anonymouscredential())
.then(() =>
db
.collection("--------")
.find({}, { sort: { project: 1 } })
.asarray()
)
.then(res => {
console.log("found docs", res);
console.log("[mongodb stitch] connected to stitch");
return res;
})
.catch(err => {
console.error(err);
});
}
edit 1:
for refactoring, i think pairing redux and redux-saga will give you very good separation of concern and a way to easily write test if you plan to do so. but overall, i think this tweak above can at least solve your issue.
Source: stackoverflow.com
Related Query
- React – Async / Await doesn’t seem to be waiting
- Why ASYNC AWAIT doesnt work well in use effect in react
- React async / await is not waiting in the calling function - but the called function is executing correctly
- Why does Async Await work with React setState?
- Is it possible to use async / await in React JS?
- How to async await in react render function?
- Using Async await in react component
- React Native Async Await in react-native-sqlite-storage
- React Hook useEffect : fetch data using axios with async await .api calling continuous the same api
- How to await multiple async await requests in React
- Async await gives syntax error when used in React component
- get latest state value after setState hook within async await block in react
- Async and Await not working in Axios React
- Async await and fetch syntax not working in React
- Making SessionStorage calls using async await in React
- Using async await to retrieve images from firebase storage in react
- React state not updating after async await call
- How to use async await with React componentDidMount() method?
- React useEffect cleanup function depends on async await result
- Async await is not waiting for response inside useEffect
- Javascript, then method not waiting for async function in React
- Is it right concept if I used Async Await with react life cycles specially with ComponentDidMount for api calls?
- Async function not waiting for results even when used inside useEffect with await
- React Hook Async await how to hold rendering on a promise
- How to use Async / Await with React hooks?
- How to integrate axios api in react js with async and await using react hooks
- await not waiting for async function to return value
- React Redux - Waiting for async api call to finish before next action is dispatched
- Handling HTTP error with async await and try and catch clause in react typescript
- React creating a mock login service with async await
More Query from same tag
- trying to merge two objects and return merged object in react
- useEffect - Can't perform a React state update on an unmounted component
- Error while formating date with a function
- Form input field value issue
- Attach current range number directly above HTML range slider thumb
- Footer Component Breaking Background
- Enzyme unit test is passing test when it should fail
- Unable to change the background-color for the <DefaultButton> inside my typescript file
- Using <a/> tag with a sticky navbar takes me to the wrong place
- How to get value in react-widgets DropdownList when select?
- What's the difference between npm run dev and npm run start in Next.js?
- mongo db node.js some error with 'db' being undefined
- Looping Lists with onClick Doesn't Work React
- How to wait for a saga to finish calling an api to execute a next function?
- What is the meaning of the three points Operator in Javascript
- How to select nested colors from theme in Material UI?
- Connecting React Dropzone Uploader and Flask
- form validation in react
- event.preventDefault( ) is NOT working in React
- React hook useCallback with get API call inside useEffect not behaving correctly
- React component not firing onClick event
- React-slick: how sync 3 sliders
- How to wrap a React component by React.cloneElement using a function?
- React-Router skip search queries on back button press
- React TS get prop for shared component
- cannot evaluate module 'react-native-maps' : Configuration with name 'default' not found
- How do I display an image on left of Material-UI AppBar, but retain the "hamburger" menu?
- Uncaught Error: Cannot add node "1" because a node with that id is already in the Store
- is there a way to use webpack defineplugin function in scss
- retrieve parent component ref for a hook