From 71b119986ceffd339b037ce319bae58c960f9461 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Tue, 28 May 2024 23:44:08 +0200 Subject: [PATCH] chore(comments): Explain how class components work >.< (#10692) --- packages/router/src/location.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/router/src/location.tsx b/packages/router/src/location.tsx index b3a3e3e1286b..26a10a995ff8 100644 --- a/packages/router/src/location.tsx +++ b/packages/router/src/location.tsx @@ -26,7 +26,9 @@ class LocationProvider extends React.Component< > { // When prerendering, there might be more than one level of location // providers. Use the values from the one above. + // (this is basically the class component version of `useLocation()`) static contextType = LocationContext + declare context: React.ContextType HISTORY_LISTENER_ID: string | undefined = undefined @@ -74,6 +76,8 @@ class LocationProvider extends React.Component< return this.props.location || this.context || windowLocation } + // componentDidMount() is not called during server rendering (aka SSR and + // prerendering) componentDidMount() { this.HISTORY_LISTENER_ID = gHistory.listen(() => { const context = this.getContext()