react-screen-capture icon indicating copy to clipboard operation
react-screen-capture copied to clipboard

Overload error when using React 18.2.0

Open askiefer opened this issue 1 month ago • 0 comments

When using this library with React 18.2.0 I get this error:

 Overload 1 of 2, '(props: Props | Readonly<Props>): ScreenCapture', gave the following error.
        Type '{ children: ({ onStartCapture }: { onStartCapture: any; }) => Element; onEndCapture: (url: string) => any; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<ScreenCapture> & Readonly<Props>'.
          Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<ScreenCapture> & Readonly<Props>'.
      Overload 2 of 2, '(props: Props, context: any): ScreenCapture', gave the following error.
        Type '{ children: ({ onStartCapture }: { onStartCapture: any; }) => Element; onEndCapture: (url: string) => any; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<ScreenCapture> & Readonly<Props>'.
          Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<ScreenCapture> & Readonly<Props>'.

    49         <ScreenCapture onEndCapture={onEndCapture}>

Seems like React 18 doesn't have implicit children props anymore.

I have implemented this very similar to the code demonstrated (see below):

 const onEndCapture = (screenCapture: string) => {
        setImagePath(screenCapture);
 }

return (
        <ScreenCapture onEndCapture={onEndCapture}>
        {({ onStartCapture }) => (
            <div>
                ....
            </div>
        )}
        </ScreenCapture>
    );

askiefer avatar May 10 '24 16:05 askiefer