Skip to content

Commit f451015

Browse files
author
Emile Frey
committed
closing alerts if switch pages
1 parent 3c81310 commit f451015

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

frontend/src/App.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Dispatch, useContext, useState } from 'react';
1+
import React, { Dispatch, useContext, useEffect } from 'react';
22
import Router from './routes/Router';
33
import Layout from './components/Layout/Layout';
44
import { connect } from 'react-redux';
@@ -10,7 +10,7 @@ import { AlertContext } from './contexts/AlertContext';
1010
import Alert from '@material-ui/lab/Alert';
1111
import { AxiosError } from './interfaces/axios/AxiosError'
1212
import { ThemeContext } from './contexts/ThemeContext';
13-
13+
import { useLocation } from "react-router-dom";
1414

1515

1616
type Error = {
@@ -34,11 +34,16 @@ function App(props: AppProps) {
3434
const { alertType, openAlert, alertMessage, handleAlertClose } = useContext(AlertContext);
3535
const { darkMode } = useContext(ThemeContext);
3636
const palletType = darkMode ? "dark" : "light"
37+
const location = useLocation().pathname
3738

38-
React.useEffect(() => {
39+
useEffect(() => {
3940
props.setAuthenticatedIfRequired();
4041
}, [props]);
4142

43+
useEffect(() => {
44+
handleAlertClose()
45+
}, [location])
46+
4247
return (
4348
<div className="App">
4449
<ThemeProvider theme={theme(palletType)}>

0 commit comments

Comments
 (0)