Remove unneeded forwardRef and memo#4096
Conversation
Release/3.2.0 alpha.3
Release/3.2.0 alpha.4
Release/3.2.0 rc.0
Release/3.2.0
Release/3.2.1 rc.0
|
@RWOverdijk is attempting to deploy a commit to the Geekyants Team Team on Vercel. A member of the Team first needs to authorize it. |
|
I'm also seeing this issue here: |
|
@RWOverdijk just curious, why memo also get removed here? |
Nice catch, I removed it because I misunderstood its purpose here. If the props don't change, the component function doesn't have to run again so I put it back. |
I've updated SkeletonCircle in this PR, too. In this case it should forward because Skeleton (used in SkeletonCircle) also forwards the ref to Box. |
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/geekyants-team/native-base/Hb1gTjx4xARcAgoL4GBq1BbBXNFK |
| import Skeleton from './Skeleton'; | ||
|
|
||
| const SkeletonCircle = ({ children, ...props }: ISkeletonProps) => { | ||
| const SkeletonCircle = ({ children, ...props }: ISkeletonProps, ref: any) => { |
There was a problem hiding this comment.
This does not appear to be correct, for one, it shouldn't pass the value into the FC like this.
There was a problem hiding this comment.
However, if you follow the other components they appear to have it but it should be ref?
There was a problem hiding this comment.
This does not appear to be correct, for one, it shouldn't pass the value into the FC like this.
It should.
However, if you follow the other components they appear to have it but it should be ref?
You mean optional? Because ForwardRefRenderFunction requires a ref, or null, not an optional ref.
There was a problem hiding this comment.
function forwardRef<T, P = {}>(render: ForwardRefRenderFunction<T, P>): ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>;and
type ForwardedRef<T> = ((instance: T | null) => void) | MutableRefObject<T | null> | null;
interface ForwardRefRenderFunction<T, P = {}> {
(props: PropsWithChildren<P>, ref: ForwardedRef<T>): ReactElement | null;
displayName?: string;
// explicit rejected with `never` required due to
// https://github.com/microsoft/TypeScript/issues/36826
/**
* defaultProps are not supported on render functions
*/
defaultProps?: never;
/**
* propTypes are not supported on render functions
*/
propTypes?: never;
}There was a problem hiding this comment.
You mean optional? Because ForwardRefRenderFunction requires a ref, or null, not an optional ref.
If we're following consistency with other components they use ref?: any though that to me is incorrect anyway since it bypasses Typescript checking.
There was a problem hiding this comment.
Sorry I know it was merged, I didn't know I had to press "Submit Review" for it to show.
There was a problem hiding this comment.
Some other components also use ref: any. It's not consistent, sure, but it's not wrong. Straightening out this inconsistency could be another PR, but brace yourself because the generics can alternate between mobile and web depending on the components you're talking about.
| return resolvedProps.isLoaded ? children : <Skeleton {...resolvedProps} ref={ref} />; | ||
| }; | ||
|
|
||
| export default memo(forwardRef(SkeletonCircle)); |
There was a problem hiding this comment.
If we follow https://reactjs.org/docs/forwarding-refs.html this is the line that should get the ref as
export default memo(forwardRef((props, ref)=> (<SkeletonCircle ref={ref} {...props} />));
There was a problem hiding this comment.
The fc is the same thing, just assigned elsewhere. It's props and then ref.
In other words the forward ref wants a function that takes props and a ref, which is what SkeletonCircle is. A function that accepts props and a ref.
So I'm not sure what you mean. This seems correct to me.
There was a problem hiding this comment.
forwardRef technically is a typed function. The second type parameter being a props without the Ref. This would've ensured typesafety, but because of how NativeBase used any in the lower level component the typecheck gets confused if you try to do it properly.
For now as long as the warning disappears I guess we should lave it at that.
There was a problem hiding this comment.
Forward ref (typescript, for that matter) doesn't care if you inline or pass through a variable.
But I'm not sure what you're suggesting. Do you mean the generics? Because while those are missing (consistently, which is not good), you can still type them in useRef. Not the prettiest, but also not the scope of this PR. It currently resolves (when typing in useRef) using no types at all.
Summary
<Hidden />was using forwardRef, but not in the right way causing issues: (https://discord.com/channels/785491682719301643/785491683336781846/889862903140847626)There were two possible fixes I could see. Remove the ref, or implement the ref properly. Since this only performs conditional rendering the ref isn't needed, so I opted to remove it.
Changelog
General Fixed - Remove unused forwardRef in Hidden component
General Fixed - Forward ref in SkeletonCircle