1- import React from 'react' ;
1+ import React , { useMemo } from 'react' ;
22import { useVersions , useActiveDocContext , useDocsVersionCandidates } from '@docusaurus/plugin-content-docs/client' ;
33import { useDocsPreferredVersion } from '@docusaurus/theme-common' ;
44import { translate } from '@docusaurus/Translate' ;
@@ -9,18 +9,6 @@ import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
99
1010const getVersionMainDoc = ( version ) => version . docs . find ( ( doc ) => doc . id === version . mainDocId ) ;
1111
12- function getApiLinks ( props , pathname , baseUrl ) {
13- if ( ! pathname . startsWith ( `${ baseUrl } reference` ) ) {
14- return [ ] ;
15- }
16-
17- try {
18- return JSON . parse ( props [ 'data-api-links' ] ) ;
19- } catch {
20- return [ ] ;
21- }
22- }
23-
2412/* eslint-disable react/prop-types */
2513export default function DocsVersionDropdownNavbarItem ( {
2614 mobile,
@@ -33,7 +21,16 @@ export default function DocsVersionDropdownNavbarItem({
3321 const { search, hash, pathname } = useLocation ( ) ;
3422 const { siteConfig } = useDocusaurusContext ( ) ;
3523 const baseUrl = siteConfig . baseUrl . endsWith ( '/' ) ? siteConfig . baseUrl : `${ siteConfig . baseUrl } /` ;
36- const apiLinks = getApiLinks ( props , pathname , baseUrl ) ;
24+ const apiLinks = useMemo ( ( ) => {
25+ if ( ! pathname . startsWith ( `${ baseUrl } reference` ) ) {
26+ return [ ] ;
27+ }
28+ try {
29+ return JSON . parse ( props [ 'data-api-links' ] ) ;
30+ } catch {
31+ return [ ] ;
32+ }
33+ } , [ props [ 'data-api-links' ] , pathname , baseUrl ] ) ;
3734
3835 const activeDocContext = useActiveDocContext ( docsPluginId ) ;
3936 const versions = useVersions ( docsPluginId ) ;
0 commit comments