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
    }

Related Query

More Query from same tag