Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust Alerts to be retrieved using Redux #304

Open
carma12 opened this issue Mar 8, 2024 · 0 comments
Open

Adjust Alerts to be retrieved using Redux #304

carma12 opened this issue Mar 8, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@carma12
Copy link
Collaborator

carma12 commented Mar 8, 2024

The Alerts are currently being handled via the useAlert custom hook. This approach requires to define the alert object from any component and consume it as a JSX element. I.e.,

import useAlerts from "src/hooks/useAlerts";

const MyComponent = () => {
  const alerts = useAlerts();

  const setAlertMessage = () => {
     alerts.addAlert(
         "success-alert",      // name: string
         "Everything went fine!",   // title: string
         "success"   // variant: AlertVariant
     );
  };

  (...)

  return (
     <>
        <alerts.ManagedAlerts />
        (...)
     </>
  );
};

export default MyComponent;

The problem with this approach is that it lacks consistency when a new Alert is defined in "short-live" components (e.g., Modal dialogs that are destroyed when closed. In some cases, they don't even disappear). Besides, a new Alert object must be defined every time to use the addAlert function, which is inefficient.

Ideally, the alert state would be handled globally (via dispatching redux action), thus allowing a single element to display alerts from multiple sources.

@carma12 carma12 changed the title Adjust useAlerts to be retrieved using Redux Adjust Alerts to be retrieved using Redux Mar 8, 2024
@carma12 carma12 added the enhancement New feature or request label Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant