Skip to content

Commit 56fb01e

Browse files
refactor: support passing ref to InputField
1 parent 2513ae1 commit 56fb01e

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

examples/default/src/components/InputField.tsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { forwardRef } from 'react';
22

33
import { KeyboardTypeOptions, StyleSheet, TextInput } from 'react-native';
44

@@ -9,22 +9,21 @@ interface InputFieldProps {
99
keyboardType?: KeyboardTypeOptions;
1010
}
1111

12-
export const InputField: React.FC<InputFieldProps> = ({
13-
placeholder,
14-
value,
15-
onChangeText,
16-
keyboardType,
17-
}) => {
18-
return (
19-
<TextInput
20-
placeholder={placeholder}
21-
style={styles.textInput}
22-
keyboardType={keyboardType}
23-
value={value}
24-
onChangeText={onChangeText}
25-
/>
26-
);
27-
};
12+
export const InputField = forwardRef<TextInput, InputFieldProps>(
13+
({ placeholder, value, onChangeText, keyboardType, ...restProps }, ref) => {
14+
return (
15+
<TextInput
16+
ref={ref}
17+
placeholder={placeholder}
18+
style={styles.textInput}
19+
keyboardType={keyboardType}
20+
value={value}
21+
onChangeText={onChangeText}
22+
{...restProps}
23+
/>
24+
);
25+
},
26+
);
2827

2928
const styles = StyleSheet.create({
3029
textInput: {

0 commit comments

Comments
 (0)