nbktechworld / full-stack-web-dev

6 stars 13 forks source link

Submit sign up form in frontend using fetch (POST request) and use http://localhost:3001 #82

Closed nbkhope closed 1 week ago

nbkhope commented 2 weeks ago

Now that we got a backend server, we should hook the frontend sign up form to that.

const [formFields, setFormFields] = React.useState({
  // initial values:
  name: '',
  email: '',
  ...
});

Then associate value and onChange property of every user input control, like:

function onFieldChange(event) {
  setFormFields({
    ...formFields,
    [event.target.name]: event.target.value
  })
}
...
  <input ... value={formFields.email} onChange={onFieldChange}
  ...
  <input ... value={formFields.birthdate} onChange={onFieldChange}

After successful sign up, redirect the user to sign page. You can do it like this:

import { useNavigate } from 'react-router-dom';

...

  const navigate = useNavigate();
  ...
    fetch(...).then(() => navigate('/signin'))
  ...
Pybite commented 1 week ago

I would like to help with this