I'm using PrimeReact toast element.
The index.js file:
import Dialogs from './components/Dialogs';
import React, { useRef } from 'react';
import { Toast } from 'primereact/toast';
const Index = () => {
const toast = useRef(null);
...
return (
<div className="card">
<Toast ref={toast} />
<Dialogs delete={delete} />
</div>
);
};
export default Status;
I want to trigger toast inside Dialogs.js (Dialogs) component:
import { Toast } from 'primereact/toast';
import React, { useRef } from 'react';
const Dialogs = ({delete}) => {
const toast = useRef(null);
return (
<>
<Toast ref={toast} />
</>
);
}
export default Dialogs;
if I remove <Toast ref={toast} />
from Dialogs
component I get the error:
Uncaught TypeError: Cannot read properties of null (reading 'show')
How can I use <Toast ref={toast} />
defined in index.js but inside Dialogs component?