#How to fix issue with ref

5 messages · Page 1 of 1 (latest)

vale latch
#

The issue is:

Type 'PropsWithoutRef<Props> & { ref: ForwardedRef<Ref>; }' is not assignable to type 'IntrinsicAttributes & Props'.
  Type 'PropsWithoutRef<Props> & { ref: ForwardedRef<Ref>; }' is not assignable to type 'Props'.
    'PropsWithoutRef<Props> & { ref: ForwardedRef<Ref>; }' is assignable to the constraint of type 'Props', but 'Props' could be instantiated with a different subtype of constraint 'Record<string, unknown>'.(2322)
function compose<Props extends Record<string, unknown>, Ref>(
  ...hocs: Array<(component: ComponentType<Props>) => ComponentType<Props>>
): (
  component: ComponentType<Props>
) => ForwardRefExoticComponent<PropsWithoutRef<Props> & RefAttributes<Ref>> {
  return (component: ComponentType<Props>) => {
    const WrappedComponent = forwardRef<Ref, Props>(
      (props, ref: ForwardedRef<Ref>) => {
        const ComposedComponent = hocs.reduceRight(
          (wrapped, hoc) => hoc(wrapped),
          component
        );

        return <ComposedComponent {...props} ref={ref} />;
      }
    );

    WrappedComponent.displayName = `Composed(${
      component.displayName || component.name || 'Component'
    })`;

    return WrappedComponent;
  };
}
summer dirge
vale latch
summer dirge
#

Is it different?

#

Closing the old copy of the question and opening a new one makes it harder for people to answer your question.