score:1
testfunction
is not returning a promise so you can't use then
or catch
and returns undefined
because well, it's not returning any thing.
try to return a promise like the example below however i am not sure what the dispatch argument supposed to do so i have removed it and hopefully this'll help:
export const testfunction = () => {
return new promise((resolve, reject) => {
otherfunction().then(( response ) => {
//do something...
resolve(response);
}).catch(( error ) => {
//do something...
reject(error);
});
});
}
score:0
when you are trying to return a promise to use it in another file, you must use the following syntax:
const testfunction = () => {
return new promise((resolve, reject) => {
if (error) {
return reject(error); // this is the value sent to .catch(error)
}
return resolve(valuetoreturn); // this is the value sent to .then(result)
});
}
this is how you create a promise to use where you want, if it has an error it will sent to catch block, otherwise you should see the console.log(result) value.
and in your external file you can use the syntax that you are using, try it in that way to see the console.log value.
here is a link to see more information: https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/promise
Source: stackoverflow.com
Related Query
- Get value returned from Promise in JavaScript
- JavaScript using async/await to make sure I retrieve value before implementation, but still get 'undefined' returned
- how to get value from a fulfilled promise in react
- How to reduce and get value from object array using javascript
- How to get value from object property in React or Javascript
- Javascript 2 arrays of objects , get a value from one array of objects and assign it to the other array of objects
- Assigned returned value from function chain into a variable in javascript
- How to get value based on key from an array of objects javascript
- How to get returned data from a function in react.js after promise
- Get value from a promise to return a link
- Get value from firebase promise in react hook
- Push the value returned from a promise into an array
- How to get the value of a promise from async function
- Can't Get the Value from Promise to Reducer
- get CSS from chrome dev tools as JavaScript object value
- Getting stale value of local state variable after response returned from promise
- How to get a value from a promise to global scope in reactjs?
- React get returned value from function with fetch
- createSlice store a value returned from a promise function in redux-toolkit
- how to return a function from react hook which internally uses a promise to get the value
- Get return and assign value from promise
- Having trouble returning more than one value from a function and assigning the returned values in a promise
- How to get parameter value from query string?
- How to get pasted value from Reactjs onPaste event
- Set React Input Field Value from JavaScript or JQuery
- React Hooks - How to get parameter value from query string
- get promise value in react component
- Get invalid value from input type number
- Javascript Redux - how to get an element from store by id
- How to get value from Select/Option component from Ant design
More Query from same tag
- React + Jest infinite loop only in test
- Getting text from React wrapped span using webdriverio
- Modifying the tooltip in react-big-calendar
- Add component to useRef object
- ReactJS + Material Design: How to get theme colors outside component?
- Trying to show card details when a user clicks on a card but receiving "not defined" error for the props I am passing in
- Correct way to use ref with Next.js for a Link and an <a>?
- How can i render out the Nav component everywhere except the Login Page?
- Reactjs : set .env file with 3 variables(prod,dev,staging) in the build folder with react build
- How to add classes to dynamically created elements in React JS?
- TypeScript workaround for rest props in React
- Patching AutoComplete In React
- How to dynamically add a class to manual class names?
- Unable to capture onClick events on Marker's children included in deck.gl@^7.1.10
- Interrupt Enter Key On ContentEditable Div In ReactJS
- React how to get parent component's property
- Integrate redux form with react tag autocomplete
- Laravel and react, How to give a notification from Laravel to my react application (Unexpected use of 'self' no restricted-globals error)
- Check Input as its being typed ReactJS
- How can I remove this switch case when the React Element name is always the same as the switch variable?
- How to use window.alert() when redirected to a page that doesn't exist in react?
- ReactJS with dynamic type objects
- I Want To Fetch Only data With A Specific Field Value On Firebase
- How can I modify React build to give me multiple JavaScript files?
- Why does my code type get a warning? "warning Missing return type on function"
- Updating state in parent with Draft editor state?
- How to import scss file as variable in react with typescript
- react onClick keycode got undefined?
- React-rails : Map multiple props
- TypeError: this.querySelectorAll is not a function while using D3Funnel in react js