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

fix(v2): remove hashbang when click on category #1999

Merged
merged 2 commits into from
Nov 15, 2019
Merged
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
11 changes: 7 additions & 4 deletions packages/docusaurus-theme-classic/src/theme/DocSidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import React, {useState} from 'react';
import React, {useState, useCallback} from 'react';
import classnames from 'classnames';

import Link from '@docusaurus/Link';
Expand All @@ -27,6 +27,11 @@ function DocSidebarItem({item, onItemClick, collapsible}) {
setCollapsed(item.collapsed);
}

const handleItemClick = useCallback(e => {
Copy link
Contributor

@yangshun yangshun Nov 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This use of useCallback is premature optimization IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe revert it?

e.preventDefault();
setCollapsed(state => !state);
});

switch (type) {
case 'category':
return (
Expand All @@ -42,9 +47,7 @@ function DocSidebarItem({item, onItemClick, collapsible}) {
'menu__link--active': collapsible && !item.collapsed,
})}
href="#!"
onClick={
collapsible ? () => setCollapsed(!collapsed) : undefined
}>
onClick={collapsible ? handleItemClick : undefined}>
{label}
</a>
<ul className="menu__list">
Expand Down