I have a modal component with a button that makes a async call with axios.
I need to remove onClick action while the call is being made to avoid unwanted clicks.
Something like this but more elegant:
const Modal = ( props ) => {
const modal = props.modal
if (!modal.loading) {
return (
<div>
<button onClick={() => props.updateModal(123)}>123</button>
</div>
);
}
else {
return (
<div>
<button>123</button>
</div>
);
}
}
const mapStateToProps = state => {
return {
modal: state.modal,
}
}
const mapDispatchToProps = dispatch => {
return {
updateModal(number){
dispatch(loadingModal(true));
// async call
return axios.post(
// async call data
)
.then((response) => {
dispatch(loadingModal(false));
dispatch(updateModal(number))
})
.catch((error) => {
console.log("Error");
}
)
}
};
}