When creating a ref in a React Native component, Typescript complains about it if you don't provide the right type.
image = React.createRef();
state = {
x: new Animated.Value(0),
y: new Animated.Value(0),
};
render() {
const {x, y} = this.state;
const imageStyle = {left: x, top: y};
return (
<Animated.View
ref={this.image} // I got warning message here
{...this.responder}
style={[styles.draggable, imageStyle]}>
{this.props.children}
</Animated.View>
)
}
const styles = StyleSheet.create({
draggable: {
position: 'absolute',
height: itemWidth,
width: itemWidth,
},
});
I got this warning
Type '{ children: ReactNode; style: ({ left: Value; top: Value; } | { position: "absolute"; height: number; width: number; })[]; current: unknown; ref: RefObject; }' is not assignable to type 'IntrinsicAttributes & AnimatedProps & { children?: ReactNode; }'. Property 'ref' does not exist on type 'IntrinsicAttributes & AnimatedProps & { children?: ReactNode; }'
createRef
line needs to be something like
image = React.createRef<some_type>();
But I don't know how to create this some_type