Skip to content

Commit c7e4180

Browse files
fix: add ref support for Web (#376)
1 parent 53bc4d3 commit c7e4180

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

js/Picker.web.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import * as React from 'react';
99
import * as ReactNativeWeb from 'react-native-web';
10-
import {forwardRef, useRef} from 'react';
10+
import {forwardRef} from 'react';
1111
import type {ViewProps} from 'react-native-web/src/exports/View/types';
1212
import type {GenericStyleProp} from 'react-native-web/src/types';
1313
import type {TextStyle} from 'react-native-web/src/exports/Text/types';
@@ -31,7 +31,10 @@ type PickerProps = {
3131
};
3232

3333
const Select = forwardRef((props: any, forwardedRef) =>
34-
ReactNativeWeb.unstable_createElement('select', props),
34+
ReactNativeWeb.unstable_createElement('select', {
35+
...props,
36+
ref: forwardedRef,
37+
}),
3538
);
3639

3740
const Picker: React$AbstractComponent<PickerProps, empty> = forwardRef<
@@ -49,8 +52,6 @@ const Picker: React$AbstractComponent<PickerProps, empty> = forwardRef<
4952
...other
5053
} = props;
5154

52-
const hostRef = useRef(null);
53-
5455
const handleChange = React.useCallback<any>(
5556
(e: Object) => {
5657
const {selectedIndex, value} = e.target;
@@ -66,7 +67,7 @@ const Picker: React$AbstractComponent<PickerProps, empty> = forwardRef<
6667
<Select
6768
disabled={enabled === false ? true : undefined}
6869
onChange={handleChange}
69-
ref={hostRef}
70+
ref={forwardedRef}
7071
value={selectedValue}
7172
{...other}
7273
/>

0 commit comments

Comments
 (0)