dappuniversity / eth-todo-list-react

Ethereum Dapp with React JS - Todo App Tutorial
50 stars 58 forks source link

How to automatically update the the list being rendered when new task is created? #2

Open BadPistol97 opened 5 years ago

BadPistol97 commented 5 years ago

I have completed the dApp here, but when I tried to submit a new task, the list did not obtained the new task from blockchain. I have to manually refresh the page to see the added task. I tried to put the loadBlockchainData() into componentDidMount() but this doesn't help as the component will mount only once. I am not sure if it is because of the async behavior of loadBlockchainData(), I tried to call loadBlockchainData() in the createTask() right after the receipt.

  createTask(content){
  this.setState({loading:true});
  this.state.todoList.methods.createTask(content).send({from:this.state.account})
  .once('receipt',(receipt)=>{
    console.log("created");
    console.log(this.state.taskCount);
  })

  this.setState({loading:false})
  this.loadBlockchainData();
}

But the data retrieved remained the same. How to retrieved the updated data immediately?