I want to implement toastify inside my toBeCalledByEventListener()
function .
actually I don’t know where I implement those in my function:
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
and
const notify = () => toast("Wow so easy!");
and
<button onClick={notify}>Notify!</button>
any suggestion please.
my function look like this:I want to implement toastify here
async function toBeCalledByEventListener() {
try {
const response = await fetch('/generate_pdf', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
});
const responseData = await response.json();
const pdfURL = responseData.pdf_url;
localStorage.setItem("pdf_url", pdfURL)
// window.open(pdfURL, '_blank');
if (!response.ok) {
throw new Error('Network response was not ok');
}
}
catch (error) {
console.error('Error fetching data:', error);
}
};
4
Answers
You just need to call the toast function wherever you need it.
I guess you want to toast where you console. try the code below:
Because the function named notify cannot pass any params, just use the function toast instead.
it is the function changes
your app.js changes :
Here I have modified your code and make it easy to use.
Make sure you have react-toastify installed. You can install it using npm
https://www.npmjs.com/package/react-toastify
Import the necessary components and styles from react-toastify at the top of your file.
This will resolve your problem.