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

Fix react-native ref type #916

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alexandernanberg
Copy link

Summary

Fix the invalid forward ref type when using native, typescript and ref options

import Svg, { Path } from 'react-native-svg'
import type { SvgProps } from 'react-native-svg'
import { Ref, forwardRef } from 'react'
const Icon = (props: SvgProps, ref: Ref<SVGSVGElement>) => (
  <Svg
    xmlns="http://www.w3.org/2000/svg"
    fill="none"
    viewBox="0 0 24 24"
	// ↓ TS complains about a mismatch between SVGSVGElement and Svg from `react-native-svg`
    ref={ref}
    {...props}
  >
    {/* ... */}
  </Svg>
)
const ForwardRef = forwardRef(SvgUserHeart)
export default ForwardRef

When using native the type must be Svg

import Svg, { Path } from 'react-native-svg'
import type { SvgProps } from 'react-native-svg'
import { Ref, forwardRef } from 'react'
-const Icon = (props: SvgProps, ref: Ref<SVGSVGElement>) => (
+const Icon = (props: SvgProps, ref: Ref<Svg>) => (
  <Svg
    xmlns="http://www.w3.org/2000/svg"
    fill="none"
    viewBox="0 0 24 24"
    ref={ref}
    {...props}
  >
    {/* ... */}
  </Svg>
)
const ForwardRef = forwardRef(SvgUserHeart)
export default ForwardRef

Test plan

Check updated snapshots

Copy link

vercel bot commented Nov 1, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
svgr ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 1, 2023 1:30pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant