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

ForwardRef for H3 #263

Closed
wants to merge 1 commit into from
Closed

ForwardRef for H3 #263

wants to merge 1 commit into from

Conversation

Vangaorth
Copy link
Contributor

Short description

This PR proposes a way to pass a view reference from a top screen to an inner component, using MainScreen and H3 as an example.

List of changes proposed in this pull request

  • H3 uses React.forwardRef to receive the ref as an input and it gives it to Factory as the second optional function parameter;
  • Factory has a generic type that cannot be used in combination with React.forwardRef, that's why ref is received as a second optional function parameter. It is later passed down to BaseTypography as a standard React view's property;
  • BaseTypography uses React.forwardRef to receive ref and to set it to its inner Text component.

The downside of this approach is that, when used in the main screen, the hook must not be explicitly typed, otherwise typescript complains about it, when passed to the H3 element. E.g.:

const aRef = useRef(null); // This works
const aRef = useRef<View|null>(null); // This does not

How to test

Using the example app, check that the ref.current is properly initialized.

@Vangaorth
Copy link
Contributor Author

Replaced by #264

@Vangaorth Vangaorth closed this May 14, 2024
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.

1 participant