score:0
Accepted answer
you can convert your pushToIPFS to be a promise instead of a callback, and just resolve it when the callback is fired.
pushToIPFS = (e) => {
return new Promise((resolve, reject) => {
ipfs.add(this.state.buffer, (err, ipfsHash) => {
resolve(ipfsHash[0].hash);
})
});
}
And since its a promise you can use async/await
.
AddMyStuff = async (e) => {
e.preventDefault()
const ipfsHash = await this.pushToIPFS();
//you have your ipfsHash defined, you can pass it to your other methods
}
Source: stackoverflow.com
Related Query
- React async method setState variable not being set in time
- State not being set by setState method
- React Router: state variable updated with setState not being passed down to Route correctly
- Why does calling react setState method not mutate the state immediately?
- Express Session Cookie Not Being Set when using React Axios POST Request
- React setState does not set state during a while loop
- useState set method not changing the value - React
- React setState hook not updating dependent element if passed a variable as opposed to explicit text
- React - component state not being set
- React render method being called every time parent rerenders
- Javascript, then method not waiting for async function in React
- React TS Variable is not updated in time
- Why is my hook variable in React not holding the state I set it to?
- setState in react function not updating in promise method
- React state variable not accurate after set state in useState hook
- Really not support async setState of React Hooks?
- React setState not firing in first time
- setState not setting state variable React
- React hooks not set state at first time
- react js state variable updates automatically without setstate method
- React hooks not being set properly with JSON API response
- State in React not changing with setState method
- useState React Hook set method does not update state immediately in onChange()
- React JSX: setting variable leads to page not being loaded
- Variable being passed as a property not rendering in react
- React useEffect: setState in return function does not update state in time
- React setState {} not setting variable
- React Hooks, setState not working with an async .map call
- React setState in onClick method not updating the DOM
- React - State not being set on initialization
More Query from same tag
- TypeError: Text.isText is not a function
- window is not defined in react server side rendering
- Send lower level component prop up to App
- How to render only 5 items in react autosuggest?
- Using npm package in Meteor via cosmos:browserify
- Props alternative to pass the component state to all the components of application in next.js
- Calculate total in dynamic form - Ant Design React
- Typescript: Type 'null' is not assignable to type error
- AutoFocus on Text Input in React Using Styled Components
- How to correctly use compose to combine HOCs that encapsulate protected routes in React-Redux
- Update component styles dynamically from state on initial load?
- How to get port forwarding to work with gatsby and vagrant or virtualbox
- Where is the config. problem in this Firebase and React App?
- material-ui 4.3.2 context menu mouse right click position
- React-three-fiber with react-spring animations
- Create simple custom progression bar in React
- useState non-instantaneous updates break function
- React Native project do not have index.ios.js or index.android.js
- If check box checked disable other, if unchecked enable all in react
- how to check if object.values in array are the same in sequence
- How do you call a function in a react-table accessor? (reactjs)
- Additional loader for pdfjs-dist in react app?
- Generating a thumbnail as a button in reactjs
- React js app - high severity vulnerability - immer
- TailwindCSS: How can I fix a header & footer to the screen while keeping scrollable content in between?
- Problem with using method setPaths ( Leaflet PolylineDecorator)
- React: useState delay issues
- Map fetched data in React with Redux Toolkit
- How to add an image slider for each react bootsrap card in a Card Deck
- this.props.children returns null in react-router