sweetalert2 / sweetalert2-react-content

Official SweetAlert2 enhancer adding support for React elements as content
MIT License
703 stars 48 forks source link

How to get the states from inside the ajax request? #113

Closed cptiwari20 closed 4 years ago

cptiwari20 commented 4 years ago

` await MySwal.fire({ title:

{inte.toUpperCase()}

, // footer: 'Copyright 2018', html: , showCancelButton: true, focusConfirm: false, confirmButtonText: ' Submit!', confirmButtonAriaLabel: 'Submit', cancelButtonText: 'Cancel', showLoaderOnConfirm: true, preConfirm: () => { const isUserLogged = Auth.loginCheck(); if (!isUserLogged) window.location = "/login";

            const token = JSON.parse(localStorage.getItem("login"));
             async function handleFormSubmit(){
              if (token) {
                const id = Auth.decode("id");
                const url = `${process.env.REACT_APP_ADMIN_SERVER_URL}/integrations/`;

                await axios
                  .post(url,
                    data, 
                      {
                      headers: {
                          authorization: token.token
                      },

                  })
                  .then(async data => {
                      // console.log(data)
                      setIntegrations(data.data);
                  }).catch(e => {
                      MySwal.showValidationMessage(
                        `Request failed: ${e.message}`
                      )
                  });
              }
            }
            handleFormSubmit()
        },
      }).then(({isConfirmed}) => {
        if(isConfirmed){
           //do something

        }
      })
  }

`

data = { ...stateObj, type: 'xyz' } When I submit the form, I get the stateObj Value == undefined. Its seems wired that, I think sweetAlert popup doesn't get any extra value from the state after fired once. If it is so, how can I get the state.

limonte commented 4 years ago

1

https://stackoverflow.com/questions/ask