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

ReactNative Button onPress target getAttribute not accessible in TypeScript

$
0
0

I use TypeScript in ReactNative to access Button target.getAttribute("data-code") but getAttribute is not accessible in onPress event. How can I reference target type? I googled around the internet but neither solution helped.

import React from 'react';import {  Alert,  Button,  GestureResponderEvent,  StyleSheet,  View,} from 'react-native';const App = () => {  const _onPressButton = (event: GestureResponderEvent) => {    Alert.alert(event.currentTarget.getAttribute('data-code'));  };  return (<View style={styles.container}><View style={styles.buttonContainer}><Button          data-code="note1"          onPress={_onPressButton}          title="Light (On)"        /></View><View style={styles.buttonContainer}><Button          data-code="Note2"          onPress={_onPressButton}          title="light (OFF)"        /></View></View>  );};const styles = StyleSheet.create({  container: {    flex: 1,    justifyContent: 'center',  },  buttonContainer: {    margin: 20,  },});export default App;

Viewing all articles
Browse latest Browse all 6290

Trending Articles



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