0

I'm new with react and redux/toolkit, I'm trying to create a fake authentication. The create account function button updates the state on second click, the first click validate the input form only.

the following code, is the create account function

const createAccount = (event) => {
    const form = event.currentTarget;
    if (form.checkValidity() === false) {
      event.preventDefault();
      event.stopPropagation();
    }

    setValidated(true);

    const findUser = userList.find((user) => user.email === email);
    // console.log(typeof findUser);
    if (validated) {
      if (findUser) {
        alert("this user already exist, login?");
      } else {
        dispatch(signup(newAccount));
      }
      navigate("/signin", { replace: true });
    }
  };

this one is my signup reducer action :

signup: (state, action) => {
      const newUser = {
        id: uuidv4(),
        ...action.payload,
      };
      return [...state, newUser];
    },
maya
  • 25
  • 1
  • 6
  • `setValidated(true)` won't make `validated` true a couple lines later in the same callback scope. This doesn't appear to be a [mcve] though, otherwise I don't see the point of this `validated` state. – Drew Reese Nov 15 '22 at 06:59

0 Answers0