Skip to content

⬅️ Back to Table of Contents

📄 useHistorySelector.ts

📊 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

Code
export function useHistorySelector<T>(
  selector: HistorySelector<T>,
  getServerSnapshot: () => T,
): T {
  const history = useHistory();
  return useSyncExternalStore(
    history.listen,
    () => selector(history),
    getServerSnapshot,
  );
}
  • Parameters:
  • selector: HistorySelector<T>
  • getServerSnapshot: () => T
  • Return Type: T
  • Calls:
  • useHistory (from @docusaurus/router)
  • useSyncExternalStore (from react)
  • selector

Type Aliases

HistorySelector<T>

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