Added redirect on visiting RemoveList component while not being logged in

This commit is contained in:
Dmitriy Shishkov 2020-09-23 21:05:56 +05:00
parent 19a4b8b43c
commit da5620519f
No known key found for this signature in database
GPG Key ID: D76D70029F55183E

View File

@ -1,4 +1,5 @@
import React, { Dispatch, SetStateAction, useEffect, useState } from 'react';
import { useHistory } from 'react-router-dom';
import { IData, ILoadingState } from '../../../types';
import { fetchCardList } from '../../../utils';
@ -16,6 +17,14 @@ const RemoveList: React.FC<props> = ({ setLoading, token, setToken }) => {
const [data, setData] = useState<IData[]>([]);
useEffect(() => fetchCardList(setData), []);
const { push: historyPush } = useHistory();
useEffect(() => {
if (!token) {
historyPush('/a/l');
}
}, [setLoading, historyPush, token]);
return (
<div id="deleteList">
{data.map((el, index) => (