Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a modern React context for identity in the app #30098

Merged
merged 1 commit into from May 19, 2024

Conversation

renchap
Copy link
Sponsor Member

@renchap renchap commented Apr 28, 2024

This removes the last usage of the old and deprecated React context API (which will be removed from React 19, and outputs deprecation warnings in React 18.3).

Modern context can be used through contextType in class components, but it makes them not explicit when consumed (it would have been this.context.me, not this.context.identity.me).

I preferred to switch to injecting an identity prop using a wrapper component inspired by withOptionalRouter, so consuming identity is explicit (this.props.identity).

This removes the last usage of the old and deprecated React context API (which will be removed from React 19, and outputs deprecation warnings in React 18.3).

Modern context can be used through `contextType` in class components, but it makes them not explicit when consumed (it would have been `this.context.me`, not `this.context.identity.me`).

I preferred to switch to injecting an `identity` prop using a wrapper component inspired by `withOptionalRouter`, so consuming identity is explicit (`this.props.identity`).
@renchap renchap added refactoring Improving code quality javascript Pull requests that update Javascript code labels Apr 28, 2024
@renchap renchap requested a review from ClearlyClaire May 2, 2024 21:07
@renchap renchap added this pull request to the merge queue May 19, 2024
Merged via the queue into mastodon:main with commit a178ba7 May 19, 2024
34 checks passed
@renchap renchap deleted the remove-legacy-identity-context branch May 19, 2024 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript Pull requests that update Javascript code refactoring Improving code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants