Skip to content

Commit

Permalink
Update react-router to v6 and refactor navigation hooks in components
Browse files Browse the repository at this point in the history
  • Loading branch information
hervedombya committed Nov 28, 2024
1 parent bf0c36d commit 33e2272
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 157 deletions.
118 changes: 33 additions & 85 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@
"react-dropzone": "^14.2.3",
"react-hook-form": "^7.49.2",
"react-query": "^3.34.0",
"react-router": "5.2.0",
"react-router-dom": "5.2.0",
"react-router": "^6.28.0",
"react-router-dom": "^6.28.0",
"react-select": "4.3.1",
"react-table": "^7.7.0",
"react-test-renderer": "^18.3.1",
Expand Down
6 changes: 3 additions & 3 deletions src/lib/components/emptystate/Emptystate.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button } from '../buttonv2/Buttonv2.component';
import { Icon, IconName } from '../icon/Icon.component';
import { LargeText } from '../text/Text.component';
import { CoreUITheme } from '../../style/theme';
import { useHistory } from 'react-router';
import { useNavigate } from 'react-router';

export type Props = {
listedResource: {
Expand Down Expand Up @@ -48,7 +48,7 @@ export const ActionWrapper = styled.div`
function EmptyState(props: Props) {
const { icon, listedResource, link, resourceToCreate, backgroundColor } =
props;
const history = useHistory();
const navigate = useNavigate();
return (
<EmptystateContainer
className="sc-emptystate"
Expand All @@ -74,7 +74,7 @@ function EmptyState(props: Props) {
icon={<Icon name="Create-add" />}
type="button"
variant="primary"
onClick={() => history.push(link)}
onClick={() => navigate(link)}
/>
</ActionWrapper>
)}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/components/tablev2/SearchWithQueryParams.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'react';
import { useLocation, useHistory } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import { TableSearch as Search, SearchProps } from './Search';

export type SearchWithQueryParamsProps = {
Expand All @@ -10,15 +10,15 @@ export type SearchWithQueryParamsProps = {
export function SearchWithQueryParams(props: SearchWithQueryParamsProps) {
const { queryParams = 'search', onChange, ...rest } = props;
const { search, pathname } = useLocation();
const history = useHistory();
const navigate = useNavigate();
const params = new URLSearchParams(search);
const initialValue = params.get(queryParams) || '';
const [value, setValue] = useState(initialValue);

function handleOnChange(value: string) {
const { onChange } = props;
params.set(queryParams, value);
history.replace(`${pathname}?${params.toString()}`);
navigate(`${pathname}?${params.toString()}`, { replace: true });
setValue(value);

if (typeof onChange === 'function') {
Expand Down
Loading

0 comments on commit 33e2272

Please sign in to comment.