fix: restore default React.AnchorHTMLAttributes
props on <PrismicLink>
#146
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Types of changes
Description
This PR restores the default
React.AnchorHTMLAttributes
props on<PrismicLink>
. This brings back support for common props likeclassName
andonClick
.See #145 for more details.
If you use
<PrismicLink>
with a component that does not behave like<a>
(for example, it does not accept props forclassName
oronClick
), the following strategies can be used in your project.In all three strategies, you would use a custom
<PrismicLink>
implementation built off<PrismicLink>
provided by@prismicio/react
.1. Custom
<PrismicLink>
using global configuration and TypeScript 4.7 Instantiation Expressions(Note: This assumes PrismicLink is configured globally via
<PrismicProvider>
to render<Link>
for internal links.)You can take advantage of TypeScript 4.7's Instantiation Expressions feature to define a custom instance of
<PrismicLink>
specific to your internal and external link React components.react-router-dom
's<Link>
is used as an example below, but this could be any component.TypeScript 4.7 is currently in beta, and we cannot expect users to always be using the latest version of TypeScript. As such, this solution will not apply to everyone.
2. Custom
<PrismicLink>
using global configuration and type parameters in JSX(Note: This assumes PrismicLink is configured globally via
<PrismicProvider>
to render<Link>
for internal links.)Similar to the above solution, a custom instance of
<PrismicLink>
can be created with the correct generic. This does not rely on bleeding-edge TypeScript features.3. Custom
<PrismicLink>
using non-global configuration(Note: This assumes PrismicLink is not configured globally via
<PrismicProvider>
to render<Link>
for internal links.)Alternatively, a custom PrismicLink instance could be configured by passing the internal/external React components directly. This ignores any global configuration provided to
<PrismicProvider>
.Checklist: