Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Get the childrens of an element in react native using useRef

import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View, TextInput, TouchableOpacity} from "react-native";
import { useRef, forwardRef} from "react";

const TextInputComponent = forwardRef<TextInput>((props, ref) => {
  return (
    <View>
      <Text>Email</Text>
      <TextInput ref={ref} placeholder="Some placeholder" />
    </View>
  );
});

export default function App() {
  const input = useRef<TextInput>(null)

  return (
    <View style={styles.container}>
      <Text>Open up App.tsx to start working on your app!</Text>
      <StatusBar style="auto" />
      <TouchableOpacity onPress={() => {
input.current?.focus();
      }}>
        <TextInputComponent ref={input} />
      </TouchableOpacity>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
});
 
PREVIOUS NEXT
Tagged: #Get #childrens #element #react #native #useRef
ADD COMMENT
Topic
Name
2+7 =