I am trying to create my TextInput component that wraps around React Native's TextInput, but applies additional styles and adds more features.
Unfortunately, I am stuck at the very start of my component... I cannot create its type.
Here's what I have so far:
import React, {JSX} from 'react';
import {StyleSheet, TextInput as RNTextInput, View,} from 'react-native';
import {useTheme} from '@/context/ThemeProvider';
export type TextInputProps = {
icon?: JSX.Element | undefined;
textInputProps?: React.ComponentProps<typeof RNTextInput>;
};
export default function TextInput({textInputProps, icon}: TextInputProps) {
const {theme} = useTheme();
return (
<View
style={[
styles.container,
{
backgroundColor: theme.backgrounds.tertiary,
borderBottomColor: theme.borders.secondary,
},
]}
>
{icon && <View style={styles.icon}>{icon}</View>}
<RNTextInput
placeholderTextColor={theme.text.lowEmphasis}
style={[
styles.input,
{color: theme.text.highEmphasis},
]}
{...textInputProps}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
height: 44,
paddingHorizontal: 12,
borderBottomWidth: 2,
},
icon: {},
input: {
flex: 1,
paddingVertical: 0,
},
});
However, I get this when spreading any additional props that might have been passed to TextInput in <RNTextInput {...textInputProps}/>:
Type ...React.ComponentProps<typeof RNTextInput> | undefined is not assignable to type React.ReactNode | undefined
My app runs fine with this error, but I want to have a clean file. What should be the value of textInputProps? in type TextInputProps?