Skip to content

⬅️ Back to Table of Contents

📄 useHistorySelector

📊 Analysis Summary

Metric Count
🔧 Functions 1
📦 Imports 2
📑 Type Aliases 1

📚 Table of Contents

🛠️ File Location:

📂 packages/website/src/hooks/useHistorySelector.ts

📦 Imports

Name Source
useHistory @docusaurus/router
useSyncExternalStore react

Functions

useHistorySelector(selector: HistorySelector<T>, getServerSnapshot: () => T): T

Parameters:

  • selector HistorySelector<T>
  • getServerSnapshot () => T

Returns: T

Calls:

  • useHistory (from @docusaurus/router)
  • useSyncExternalStore (from react)
  • selector

Internal Comments:

// by default H.History<LocationState = unknown> (x2)

Code
export function useHistorySelector<T>(
  selector: HistorySelector<T>,
  getServerSnapshot: () => T,
): T {
  // by default H.History<LocationState = unknown>
  const history = useHistory();

  return useSyncExternalStore(
    history.listen,
    () => selector(history),
    getServerSnapshot,
  );
}

Type Aliases

HistorySelector<T>

type HistorySelector<T> = (history: H.History) => T;

Generated by Syntax Scribe