I'm trying to pass in a transcript from the frontend (which the user gives by talking into a mic), and then that data will go to the backend which will return a JSON object back to the frontend. How do I make it so that my website redirects the user to a loading screen while that process (data from the frontend to backend to frontend) is taking place, and then ultimately once that process is done, it will redirect it from that loading screen to a "results page" that will display that data?
I'm using react version 6.14.13
. Does anyone know anything I could do?
These functions in my "main page" is what is going to handle this:
class Product extends Component {
constructor() {
super()
this.state = {
// Backend API data
data: {"data": {}}
}
}
handleSending() {
const options = {
method: "POST",
headers: {
'Content-Type': 'application/json;charset=utf-8',
},
body: JSON.stringify(this.state.text)
};
fetch("http://127.0.0.1:5000/", options)
.then(response=> response.json())
.then(json => this.setState({data: json}))
.then(this.handleRedirect())
}
handleRedirect() {
// REDIRECT USER TO LOADING PAGE
// ONCE PROCESS IS DONE, REDIRECT USER TO "RESULTS PAGE"
}
}