Paratron / hookrouter

The flexible, and fast router for react that is entirely based on hooks
1.5k stars 92 forks source link

navigate throws error with error log showing "wth" #109

Open grayson-solutions opened 4 years ago

grayson-solutions commented 4 years ago

I have a button which on click uses axios to save the form data. I have that in a try catch. The axios request works just fine, but when I try to navigate to a new "page", an error is thrown. When I catch and log the error it just shows: wth !

const SaveEvent = async () => {
        let savedOk = false
        setSaving(true)
        const data = {
            ...
        }
        try {
          const result = await axios({
            method: 'post',
            url: 'http://localhost:49505/principal/api/AddEvent',
            headers : {'content-type' : 'application/json'},
            data: JSON.stringify(data)
          })
          if (result.data === "ok") {
                alert("Evening Saved")
                savedOk = true
                navigate('/admin/events', true);

          }
      } catch (e) {
        console.log(e);
        alert("Error Saving Data")            
      } finally {
        if (!savedOk) setSaving(false)
      }; 
  }

...

<button className="btn right waves-effect waves-light" id="btnAddEventSave" onClick={SaveEvent}><i className="material-icons left">save</i> SAVE</button>

...

{saving &&
    <div className="progress">
        <div className="indeterminate"></div>
    </div>
    }

if I move the navigate out of the try/catch, I get an error in the console saying uncaught error...

The navigation works ok, but I don't want to have to check for a wth error in my catch. What am I doing wrong>

Mrbeyond commented 4 years ago

I also observed the same in my app as well. I wish to know what is really causing that.

howesteve commented 4 years ago

Same here... "Uncaught wth" when navigating.