Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
vietanhtran16 committed Jan 7, 2025
1 parent 893ae1e commit ff94155
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ import { useToastNotificationContext } from '../context/ToastNotificationContext
import { ToastNotificationsMap } from './subcomponents/ToastNotificationsMap'
import styles from './ToastNotificationsList.module.scss'

const toastNotificationListId = 'toast-notifications-list'

export const ToastNotificationsList = (): JSX.Element => {
const { notifications, removeToastNotification } = useToastNotificationContext()
const [toastContainer, setToastContainer] = useState<Element | null>(null)

useEffect(() => {
let container = document.querySelector('[data-testid="toast-notifications-list"]')
// this is to ensure that the container is created only once. Regardless of how many KaizenProvider is set up, they will also reuse the same container.
let container = document.querySelector(`[id="${toastNotificationListId}"]`)
if (!container) {
container = document.createElement('div')
container.setAttribute('data-testid', 'toast-notifications-list')
container.setAttribute('id', toastNotificationListId)
container.setAttribute('role', 'status')
container.className = styles.toastNotificationsList
document.body.appendChild(container)
Expand Down

0 comments on commit ff94155

Please sign in to comment.