There are 2 event handlers that handle passwords. The first inputPassword writes the value from its input to state the second inputPasswordRE writes the value of input and compares it to the value from inputPassword. Since setState works asynchronously, even if the same values are entered, the check fails, so how in inputPasswordRE its previous state is compared (When you enter in the password field - 12345 and in the re_password field - 12345, their values password === re_password will be false.). How to correctly write setState in inputPasswordRE so that did the comparison work correctly?
const inputPassword = (e) => {
setState(({ ...state, password: e.target.value }));
};
const inputPasswordRE = (e) => {
setState({ ..state, re_password: e.target.value });
if (password === re_password) {
alert(`SUCCESS`)
} else {alert(`ERROR`)}
};