Skip to content

Conversation

ian-wd
Copy link

@ian-wd ian-wd commented May 28, 2025

  • Fixes react 19 ref cleanup TS error
  • Dropped global JSX usage and imports JSX type from react

React19 Cleanup function refs

Due to the introduction of ref cleanup functions, returning anything else from a ref callback will now be rejected by TypeScript. The fix is usually to stop using implicit returns, for example:

- <div ref={current => (instance = current)} />
+ <div ref={current => {instance = current}} />

The original code returned the instance of the HTMLDivElement and TypeScript wouldn’t know if this was supposed to be a cleanup function or if you didn’t want to return a cleanup function.

@ian-wd ian-wd requested a review from iBotPeaches May 28, 2025 01:18
@iBotPeaches iBotPeaches merged commit 25f50fa into master May 28, 2025
1 check passed
@iBotPeaches iBotPeaches deleted the typescript-fixes branch May 28, 2025 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants