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.
Resolves #3483
Playground:
playgrounds/react/pages/menu/test-menu.tsx
How
I created a new
NewRefProp
type, but we could easily refactor the existingRefProp
type.While checking for unknown helps to hide ref from potential props when it's not applicable, this approach might not cover all cases. If ref appears as unknown but the component actually expects it, our method might not work as intended. In such scenarios, we may need to consider removing the condition from the type. I personally think it's okay to force typing components properly.
I'm currently using
React.ComponentWithRef
. While I could manually construct the type, adding support for ref callbacks triggers a warning from React.Important to note
For cases where ref is used as a regular prop (e.g.,
({ ref }: { ref: boolean }) => null
), React overrides the prop to be optionalref?: boolean
. Additionally, using ref as a string causes issues. This problem also exists with the current implementation. As a best practice, users should avoid naming propsref
unless they're used as refs.@RobinMalfait