It is HOC, I have follow errors:
Type 'Pick, "children" | Exclude> & { ...; }' is not assignable to type 'IntrinsicAttributes & P & { children?: ReactNode; }'
Type 'Pick, "children" | Exclude> & { ...; }' is not assignable to type 'P'.
'Pick, "children" | Exclude> & { ...; }' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'TextInputProps'.
How repair it?
import { View, ViewStyle, StyleProp, NativeSyntheticEvent, TextStyle, TextInputProps } from 'react-native';
type Props = {
styleWrapper?: StyleProp<ViewStyle>;
style?: StyleProp<TextStyle>;
title?: string;
value?: string;
onFocus?: (e: NativeSyntheticEvent<any>) => void;
onBlur?: (e: NativeSyntheticEvent<any>) => void;
onChange?: (text: string) => void;
onReset?: () => void;
withReset?: boolean;
};
export const withInputWrapper = <P extends TextInputProps = TextInputProps>(
InputComponent: React.ComponentType<P>
): React.FC<P & Props> => {
return ({ styleWrapper, style, title, value, onFocus, onBlur, onChange, onReset, withReset = true, ...props }) => {
const onFocusHandler = ...
const onBlurHandler = ...
const onChangeHandler = ...
return (
<View style={styleWrapper}>
<View style={s.inputWrapper}>
<InputComponent // <-- here
{...props}
onChange={onChangeHandler}
value={value}
style={style}
onBlur={onBlurHandler}
onFocus={onFocusHandler}
/>
</View>
</View>
);
};
};