Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6212

How to create type when using createRef for Animated.View in TypeScript

$
0
0

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


Viewing all articles
Browse latest Browse all 6212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>