V
V
VloVer2020-07-28 11:33:25
React
VloVer, 2020-07-28 11:33:25

Why is state only updated after second click of react hook?

const deleteUser = () => {
      axios.get(`http://localhost:3001/users/${user.id}`)
          .then(({ data }) => {
            console.log(data)
            setDataa(data)
            axios.get(`http://localhost:3001/lists`)
            .then(({ data }) => {
               data.map(l => {
                  if(dataa && l.userId === dataa.id){
                     console.log(l)
                  }
               })
            })
            
            })
         .catch(e => {
            alert('Ошибка');
         }) 
   }

Why is state only updated after second click of react hook? l is not output to the console on the first click, but on the second click

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question