Reputation: 257
I want to call two functions within setState function of React native , I think its Possible and I think that there is only error in my syntax so could you please correct my code , cancelationButnEdit function is not runing I am debuging with simple console.log , there is no output at all , i guess because its not accessing the function .
....
const list = this.state.data;
list[index] = task;
this.setState({data : list},
() => { this.cancelationButnEdit()},
() => {this.saveTaskList()});
}
Upvotes: 0
Views: 34
Reputation: 2989
You have to to all your functions calls in on call back
const list = this.state.data;
list[index] = task;
this.setState({data : list}, () => {
this.cancelationButnEdit()
this.saveTaskList()
});
Upvotes: 0
Reputation: 2081
Why not call both function from the same callback? Because setState
has only one callback as it's second parameter. So you have to write it in this way:
this.setState({
data : list
}, () => {
this.cancelationButnEdit();
this.saveTaskList()
});
Upvotes: 1