Skip to content

Commit

Permalink
chore(comments): Explain how class components work >.< (#10692)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored May 28, 2024
1 parent 7d60707 commit 71b1199
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/router/src/location.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof LocationContext>
HISTORY_LISTENER_ID: string | undefined = undefined

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 71b1199

Please sign in to comment.