【发布时间】:2020-07-10 14:18:56
【问题描述】:
所以在我的 React Native 应用程序中,我想按照 here 的指导集成 this 滑块。
问题是,我想访问useRef() 的.current 属性的方法setLowValue(),正如在the guidance website 的末尾所指定的那样。我将.current 打印到控制台并看到setLowValue() 被指定为一个函数,所以它肯定存在。为什么我无法访问它?
这是我的代码:
imports ...
type Props = {
size: number;
setSize: (size: SizeState) => void;
};
const Slider: React.FC<Props> = ({size, setSize}) => {
const slider = useRef(66); // set slider to inital value
console.log('slider ', slider.current.initialLowValue); // doesn't work: "slider.current.initialLowValue is not a function"
return (
<View style={styles.container}>
<RangeSlider
ref={slider}
max={70}
min={50}
step={1}
initialLowValue={size} // I want to have access to this property
value={size}
onValueChanged={value => setSize({size: value})}
/>
</View>
);
};
function mapStateToProps(state: RootState) {
return {
height: state.sizeResult.size,
};
}
const mapDispatchToProps = {
setSize,
};
export default connect(mapStateToProps, mapDispatchToProps)(Slider);
我们将不胜感激!
【问题讨论】:
标签: reactjs react-native react-hooks use-ref