I have multiple buttons on a page, when user click on each button it should show a loading, I do this with a class, but there is a problem, it add loading to all button but I just need to add class to this button (which is clicked not all!)
You can see a simple demo Here
handleClick = (e) => {
this.setState({
loading: 'loading'
})
}
I am aware that all buttons use the same state but how can I use changed state on clicked button not all. what is the best practice?
should I use ref ? or should I use multiple states?
but I don't know how many buttons will be add on this page in the future. any idea to give a solution or trick.
apiand when it give success, loading should remove, but this happen on other function, not handleClick, so how can I select that button for remove loading class? @ankitkanojia