Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Forward Ref React Native Example

import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, Button, TouchableOpacity } from 'react-native';
import React from 'react';

export default function App() {
function q()
{

  console.log(hello.current.props.title);
}
  const hello = React.createRef();
    return (
    <View style={styles.container}>

<TouchableOpacity  onPress={()=>q()}>
<Text>
 Invoke Fancy Button
  </Text>

</TouchableOpacity>
<FancyButton ref={hello}/>  
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

const FancyButton = React.forwardRef((props, ref) => (
  <Button ref={ref} id="myId" title="FancyButton" />
 
));
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #Forward #Ref #React #Native #Example
ADD COMMENT
Topic
Name
3+3 =