EatTheBlocks Forum

Misunderstanding at DAY13-Multisig Wallet

Hello Everyone,

I hope you are all well.
In the frontend part in the updateCurrentTransfer function I don’t understand the following line:
setCurrentTransfer({…currentTransfer, alreadyApproved});

Could you explain me what it means please?
I have looked to some online documentation but I still don’t understand.

Here is the entire function:

async function updateCurrentTransfer() {

const currentTransferId = (await contract.methods

  .nextId()

  .call()) - 1;

if(currentTransferId >= 0) {

  const currentTransfer = await contract.methods

    .transfers(currentTransferId)

    .call();

  const alreadyApproved = await contract.methods

    .approvals(accounts[0], currentTransferId)

    .call();

  setCurrentTransfer({...currentTransfer, alreadyApproved});

}

}

Thank you for your help

Take care

Pierre

Hey!
Three dots syntax ( ‘…’ ) is the spread operator in React.
If you do setCurrentTransfer(alreadyApproved) , the resulting state object will just be { alreadyApproved: alreadyApproved}. The new value is not merged into the old one, it is just replaced.
setCurrentTransfer({…currentTransfer, alreadyApproved}) would give you your original state object and only update the one thing you changed.

Thank you very much :slight_smile: