- Create Components folder under src folder
- Add PassingParameterViaOnclick2.js file and add below Code
import React from "react";
import { Button, Text, View } from "react-native";
const onClickEvent = id => {
alert(id);
};
const PassingParameterViaOnclick2 = () => {
return (
<View>
<Text>
React passing parameter via onclick event using Arrow function
</Text>
<Button
title="Submit"
value="buttonValue"
onPress={() => {
onClickEvent(10);
}}
/>
</View>
);
};
export default PassingParameterViaOnclick2;
- Open App.js file and update code as below\
import React from 'react';
import { View,StyleSheet } from 'react-native';
import PassingParameterViaOnclick2 from './src/components/PassingParameterViaOnclick2'
const App=()=> {
return (
<View style={styles.container}>
<PassingParameterViaOnclick2/>
</View>
);
}
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
paddingTop:80
},
});
No comments:
Post a Comment