Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
is this the right way to fetch data while usine usestate hooks? i use usestate hook but i don't know if this the right way to fetch data

enter image description here

i just wrote the code and fetch usestate data like that cause I didn't find some source to how doing it in the form section I use onChange={event => setFirstName(event.target.value)} I don't know where is the problem cause the data didn't show up in the database

function OrderCP(props) {
  const [firstName, setFirstName] = useState('');
  const [lastName, setLastName] = useState('');
  const [email, setEmail] = useState('');
  const [mobileNumber, setMobileNumber] = useState('');
  const [adress, setAddress] = useState('');
  const [city, setCity] = useState('');
  const [size, setSize] = useState('');
  const [quantity, setQuantity] = useState('1');






  function onOrderSubmit ()  {
  fetch('http://localhost:3000/orderCP', {
      method: 'post',
      mode: 'cors',
      headers: {'Content-Type': 'application/json'},
      body: JSON.stringify({
        firstname: setFirstName,
        lastname:setLastName,
        email: setEmail,
        mobilenumber: setMobileNumber,
        adress: setAddress,
        city: setCity,
        size:setSize,
        quantity: setQuantity

      })
    })
      .then(response => response.json())
      .then(user => {
        if (user.id) {
         return (
          this.props.loadUser(user),
         <Link to ='/orderCP/orderCompletedCP' /> )
        }
      })
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

the "set" methods are functions to set the values of the useState variables.

For example

  const [firstName, setFirstName] = useState('')

the status of firstName is initial an empty string. To set the variable you call

setFirstName('newString')

after that you can use firstName to access the value.

You should change your body

`body: JSON.stringify({
    firstname: firstName,
    lastname:lastName,
    email: email,
    mobilenumber: mobileNumber,
    adress: address,
    city: city,
    size:size,
    quantity: quantity

  })`
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda