Add immutable forwardRef typing alternative#323
Conversation
| )); | ||
| ``` | ||
|
|
||
| `forwardRef` alternative without mutability: |
There was a problem hiding this comment.
i dont understand what "without mutability" means. do you mind elaborating in here? how does this materially differ from the example above?
There was a problem hiding this comment.
React.forwardRef<HTMLElement, Props> assigns the type ((instance: T | null) => void) | MutableRefObject<T | null> | null to the ref parameter. It's a MutableRefObject<T | null>, unlike with React.Ref<T>. The latter returns ((instance: T | null) => void) | RefObject<T> | null, which seems to be an improvement.
There was a problem hiding this comment.
which seems to be an improvement.
We should explain this in the cheatsheet where this would be an improvement. It would always be an improvement then you should propose the change to @types/react.
There was a problem hiding this comment.
Thank you for the discussion!
It appears that an opposing issue was raised and a PR has been merged to make the ref parameter of forwardRef mutable.
There was a problem hiding this comment.
wow. we both learned something today...
No description provided.