react-native-picker-select icon indicating copy to clipboard operation
react-native-picker-select copied to clipboard

Icon prop type error

Open simvi opened this issue 3 years ago • 4 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

The type of Icon was invalid for Icon prop.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-picker-select/index.d.ts b/node_modules/react-native-picker-select/index.d.ts
index 9f111bc..09644ca 100644
--- a/node_modules/react-native-picker-select/index.d.ts
+++ b/node_modules/react-native-picker-select/index.d.ts
@@ -83,7 +83,7 @@ export interface PickerSelectProps {
     pickerProps?: CustomPickerProps;
     touchableDoneProps?: CustomTouchableDoneProps;
     touchableWrapperProps?: CustomTouchableWrapperProps;
-    Icon?: React.ReactNode;
+    Icon?: React.FC;
     InputAccessoryView?: React.ReactNode;
 }
 

This issue body was partially generated by patch-package.

simvi avatar Feb 08 '23 09:02 simvi

@simvi Do you recall if running patch-package for this library was an incredibly slow operation? I'm currently trying to run a patch on it myself and it seems like it's hanging.

tdraper-dev avatar Mar 09 '23 17:03 tdraper-dev

@simvi Do you recall if running patch-package for this library was an incredibly slow operation? I'm currently trying to run a patch on it myself and it seems like it's hanging.

We were also struggling with npm, using yarn solved the problem.

hrdyjan1 avatar Jul 17 '23 13:07 hrdyjan1

To anyone interested, this is why Icon must be a React.FC, it is being called like a component here, not a ReactNode.

If Icon was truly meant to be a ReactNode, renderIcon would look like this:

renderIcon() {
    const { style, Icon } = this.props;

    if (!Icon) {
        return null;
    }

    return (
        <View
            testID="icon_container"
            style={[defaultStyles.iconContainer, style.iconContainer]}
        >
            {Icon}
        </View>
    );
}

P.S. To get around this issue I created a Functional Component to input to Icon typed as a React.FC with a // @ts-expect-error.

devinMcArthur avatar Aug 30 '23 19:08 devinMcArthur

dupe of #478 - prs to fix this are welcome

lfkwtz avatar Nov 27 '23 15:11 lfkwtz