Yes it is possible. You can have a state called isLoading
and you can set it to true
when you submit a post
request and you can check for isLoading
before rendering your component like below.
if(isLoading) {
return (<Spinner />)
}
And you can use toast to show success/error
message after post
method is executed.
Like below
toast.error('Sorry request failed')
or
toast.success('Request successfull')
But before use toast you have wrap your App
component in toast container
like below.
import React from 'react';
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
function App(){
const notify = () => toast("Wow so easy!");
return (
<div>
<button onClick={notify}>Notify!</button>
<ToastContainer />
</div>
);
}