3

晚上好,如果有人可以帮助我,我将不胜感激。

chakra用来防止通知显示是否已经显示

但是现在我将通知分成了另一个组件:

import React from 'react';
import { createStandaloneToast } from '@chakra-ui/react';
import theme from '../theme';
    
const Notification = (title, description, status) => {
    const toast = createStandaloneToast({ theme: theme });

    toast({
        title: title,
        description: description,
        status: status,
        duration: 3000,
        position: 'bottom-right',
        isClosable: true,
      });

    return <></>;
};

export default Notification;

在我的组件中,我按如下方式使用它:

import React, { useContext } from 'react';
...

const RemoveToDo = () => {
    const remove = () => {
        ...
        Notification('Tarea eliminada.', 'Has eliminado la tarea.', 'success');
    };
};

你怎么能阻止他们现在重复?

当我使用useToast并且我在另一个组件中没有单独的通知时,我能够防止它们被重复:

const id = 2;
if (!toast.isActive(id)) {
    toast({
        id: 2,
        title: 'Error al crear la tarea.',
        description: 'Ya tienes una tarea con esa descripción.',
        status: 'warning',
        duration: 3000,
        position: 'bottom-right',
        isClosable: true,
    });
};
4

0 回答 0