Refs được sử dụng như thế nào trong React?
Refs được sử dụng như thế nào trong React?
Ref giữ một giá trị/ tham chiếu bền qua các lần render mà thay đổi không gây render lại; thường để truy cập trực tiếp component native.
import { useRef } from "react";
import { TextInput, Button, View } from "react-native";
function Form() {
const inputRef = useRef<TextInput>(null);
return (
<View>
<TextInput ref={inputRef} placeholder="Tên" />
<Button title="Focus" onPress={() => inputRef.current?.focus()} />
</View>
);
}
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.