What is the difference between navigation.navigate('RouteName') and navigation.push('RouteName') in a Stack Navigator?
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: "navigate will navigate to the route if it is already in the stack, otherwise push a new one, while push will always add a new screen to the stack". Trong Stack Navigator, navigate xử lý theo tên route: nếu màn hình đó đã có trong ngăn xếp thì quay về nó (cập nhật params) thay vì tạo bản mới, nếu chưa có thì mới đẩy thêm; push luôn đẩy một bản mới lên đỉnh ngăn xếp, nên có thể mở cùng một màn hình chi tiết nhiều lần chồng lên nhau. "navigate and push are the same and interchangeable" sai vì hai hàm khác nhau đúng ở điểm trên. "navigate can only be used for the initial route" sai vì navigate dùng được mọi lúc, route ban đầu do initialRouteName quyết định. "push will remove the previous screen from the stack" mô tả hành vi của replace, còn push giữ nguyên màn hình trước nằm bên dướ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