What prop is used to pass data between screens in React Navigation?
4 phương ánCó giải thích
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "route.params". Trong React Navigation, màn hình gửi dữ liệu bằng
navigation.navigate('Details', {
itemId: 42
}), còn màn hình nhận đọc lại qua đối tượng route mà navigator truyền vào làm prop, cụ thể là route.params.itemId, hoặc lấy route bằng hook useRoute. params là kho tham số gắn với từng route trong state điều hướng. "navigation.state" là cách của React Navigation 4 trở về trước (navigation.state.params), đã bị bỏ từ phiên bản 5 khi tách navigation và route thành hai prop riêng. "route.data" sai vì đối tượng route chỉ có các trường như key, name, params, không có trường data. "navigation.params" sai vì navigation là đối tượng chứa các hàm điều hướng như navigate, goBack, setParams, nó không lưu tham số của màn hình hiện tại.
Cùng chương 5
Consider the following component using useIsFocused and useEffect. What will be the behavior if the component is initially unfocused and then gets focused?
import React, { useEffect } from 'react';
import { Text } from 'react-native';
import { useIsFocused } from '@react-navigation/native';
function ProfileScreen() {
const isFocused = useIsFocused();
useEffect(() => {
if (isFocused) {
console.log('ProfileScreen is now focused');
}
}, [isFocused]);
return <Text>Profile Screen</Text>;
}Có lời giảiCâu hỏiWith hook in React Navigation, what will happen if you call useFocusEffect inside a functional component but provide an empty dependency array?Có lời giảiCâu hỏiIn React Navigation, which hook should you use to get access to route parameters inside a functional component?Có lời giảiCâu hỏiCả 24 câu của chủ đề24 câu