src: replace React Router history with navigate

React Router v6 now has useNavigate() instead of useHistory.
useNavigate() is equivalent to useHistory().push();
This commit is contained in:
Jacob Kozol 2021-11-16 12:34:22 +01:00 committed by jkozol
parent 50a515db1e
commit b71aa75df3
2 changed files with 7 additions and 7 deletions

View file

@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react';
import { useHistory } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import { Router } from './Router';
import '@patternfly/patternfly/patternfly-addons.css';
import './App.scss';
@ -13,7 +13,7 @@ import PermissionDenied from './Components/LandingPage/PermissionDenied';
const App = (props) => {
const [ permission, setPermission ] = useState(false);
const history = useHistory();
const navigate = useNavigate();
useEffect(() => {
const registry = getRegistry();
@ -28,7 +28,7 @@ const App = (props) => {
});
const unregister = insights.chrome.on('APP_NAVIGATION', (event) =>
history.push(`/${event.navId}`)
navigate(`/${event.navId}`)
);
return () => {
unregister();

View file

@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import ImageCreator from './ImageCreator';
import { useHistory } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import componentTypes from '@data-driven-forms/react-form-renderer/component-types';
import { Button, Spinner } from '@patternfly/react-core';
import { ExternalLinkAltIcon } from '@patternfly/react-icons';
@ -108,7 +108,7 @@ const onSave = (values) => {
const CreateImageWizard = () => {
const dispatch = useDispatch();
const history = useHistory();
const navigate = useNavigate();
const [ user, setUser ] = useState();
useEffect(() => {
(async () => {
@ -117,7 +117,7 @@ const CreateImageWizard = () => {
})();
}, []);
return user ? <ImageCreator
onClose={ () => history.push('/landing') }
onClose={ () => navigate('/landing') }
onSubmit={ ({ values, setIsSaving }) => {
setIsSaving(() => true);
const requests = onSave(values);
@ -129,7 +129,7 @@ const CreateImageWizard = () => {
}, true));
})))
.then(() => {
history.push('/landing');
navigate('/landing');
dispatch(addNotification({
variant: 'success',
title: 'Your image is being created',