Skip to content

Commit

Permalink
fix match usage (#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin McBee authored Mar 21, 2020
1 parent 954a715 commit 9d15bc5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/site/src/components/scroll-to-top.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import React, { useEffect, useRef } from 'react';
import { useLocation } from 'react-router-dom';
import { useMarkdownPage } from 'react-static-plugin-md-pages';

const parsePathname = pathname => {
const match = pathname && pathname.match(/#[a-z|-]+/);
return match && match[1];
};

export const ScrollToTop = () => {
const inputRef = useRef(null);
const location = useLocation();
const md = useMarkdownPage();

const hash =
location.hash ||
(location.pathname && location.pathname.match(/#[a-z|-]+/));
const hash = location.hash || parsePathname(location.pathname);

useEffect(() => {
if (hash && md) {
Expand Down

0 comments on commit 9d15bc5

Please sign in to comment.