When the else condition is triggered in the callback function, I am using useHistory hook to redirect, but am getting an error showing:
Uncaught TypeError: Cannot read properties of undefined (reading 'push')
I tried using Redirect as well, but it did not redirect but the welcome message alert is showing
The code:
export default function Deposit() {
const [alanInstance, setAlanInstance] = useState();
const { isAuth } = useSelector((state) => state.login);
const dispatch = useDispatch();
let history = useHistory();
const depositPage = useCallback(() => {
if (!isAuth) {
alanInstance.playText("You are not logged in, please login")
} else {
alanInstance.playText("You are going to start your deposit")
alert('Welcome Message');
history.push("/deposit");
// return <Redirect to='/deposit' />
}
}, [alanInstance, isAuth ])
}