Skip to content

Showing Notifications on state/context change #58

Answered by rtivital
MattHeslington asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Matt, the best way to do this is to integrate notifications.showNotification handler directly into where state is managed, for example in function where you fetch the data:

  const [loading, setLoading] = useState(false);
  const notifications = useNotifications();

  const startLoading = () => {
    setLoading(true);
    notifications.showNotification({ loading: true, message: 'Loading your data' });
  }

You can also subscribe to state via useEffect at any component (not recommending this though as it will be hard to debug this in future):

  useEffect(() => {
    loading &&
      notifications.showNotification({
        loading: true,
        message: "Loading your data",
      });
  }, 

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@MattHeslington
Comment options

Answer selected by MattHeslington
Comment options

You must be logged in to vote
2 replies
@cstrat
Comment options

@MattHeslington
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants