Skip to content

Commit

Permalink
fix: eliminate keyboard shortcuts UI flash (#1021)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxsan committed Jul 21, 2021
1 parent 9da72a8 commit c8e0c27
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/docsearch-react/src/DocSearchButton.tsx
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useMemo } from 'react';

import { ControlKeyIcon } from './icons/ControlKeyIcon';
import { SearchIcon } from './icons/SearchIcon';
Expand All @@ -25,14 +25,13 @@ export const DocSearchButton = React.forwardRef<
>(({ translations = {}, ...props }, ref) => {
const { buttonText = 'Search', buttonAriaLabel = 'Search' } = translations;

const [key, setKey] = useState<
const key = useMemo<
typeof ACTION_KEY_APPLE | typeof ACTION_KEY_DEFAULT | null
>(null);

useEffect(() => {
>(() => {
if (typeof navigator !== 'undefined') {
setKey(isAppleDevice() ? ACTION_KEY_APPLE : ACTION_KEY_DEFAULT);
return isAppleDevice() ? ACTION_KEY_APPLE : ACTION_KEY_DEFAULT;
}
return null;
}, []);

return (
Expand Down

0 comments on commit c8e0c27

Please sign in to comment.