Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing the depreciated useHistory() hook with the new useNavigate() hook #1452

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions apps/base-docs/src/pages/tutorials/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import clsx from 'clsx';
import styles from './styles.module.css';
import tutorialData from '../../../tutorials/data.json';
import authors from '@app/base-docs/static/json/authors.json';
import { useHistory, useLocation } from 'react-router-dom';
import { useNavigate, useLocation } from 'react-router-dom';

const TagList = [
'all',
Expand Down Expand Up @@ -47,23 +47,23 @@ function TagChip({ tag, isSelected, setSelectedTag }) {
);
}

const handleContainerClick = (event, tutorial, history) => {
const handleContainerClick = (event, tutorial, navigate) => {
if (event.target.closest('a')) return;
history.push(`/tutorials${tutorial.slug}`);
navigate(`/tutorials${tutorial.slug}`);
};

const handleClick = (event) => {
event.stopPropagation();
};

function TutorialListCell({ tutorial }) {
const history = useHistory();
const navigate = useNavigate();
const authorData = authors[tutorial.author];
return (
// <Link to={`/tutorials${tutorial.slug}`}>
<div
onClick={(event) => {
handleContainerClick(event, tutorial, history);
handleContainerClick(event, tutorial, navigate);
}}
role="button"
tabIndex={0}
Expand Down Expand Up @@ -105,7 +105,7 @@ const TITLE = 'Base Builder Tutorials';

export default function Tutorials() {
const [selectedTag, setSelectedTag] = useState('all');
const history = useHistory();
const navigate = useNavigate();
const query = useQuery();

useEffect(() => {
Expand All @@ -117,9 +117,9 @@ export default function Tutorials() {

const selectTag = useCallback(
(tag) => {
history.push(`?tag=${tag}`);
navigate(`?tag=${tag}`);
},
[history],
[navigate],
);

return (
Expand Down