我尝试使用 react-native-raw-bottom-sheet 作为可重用组件。我创建了一个父组件,问题是当我尝试给出值时出现此错误。
TypeError: undefined is not an object (evaluating 'refRBSheet.current.open')
父组件
import React from 'react';
import RBSheet from 'react-native-raw-bottom-sheet';
const CustomActionSheet = (props) => {
const { ref, Content, height } = { ...props };
return (
<RBSheet
height={height}
ref={ref}
closeOnDragDown={true}
closeOnPressMask={true}
customStyles={{
wrapper: {
backgroundColor: 'transparent',
},
draggableIcon: {
backgroundColor: '#000',
},
}}
>
{Content}
</RBSheet>
);
};
export default CustomActionSheet;
子组件
<View style={styles.chsDlvrBtn}>
<Button title="Choose Delivery" onPress={() => refRBSheet.current.open()} />
</View>
<CustomActionSheet
ref={refRBSheet}
Content={
<View style={styles.view}>
{MONTH_OF_YEAR.map((val) => {
return (
<Chip mode="outlined" onPress={() => {}} style={styles.chp}>
{val}
</Chip>
);
})}
</View>
}
/>
参考挂钩
const refRBSheet = useRef()
这里出了什么问题。谢谢,提前!!!