Consider the following code using useIsFocused. What will be logged if the component is initially focused and then loses focus?
4 phương ánCó giải thíchTrung bình
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Khi sử dụng hook `useIsFocused`, chúng ta có thể kiểm tra xem một thành phần có đang được tập trung hay không. Trong ví dụ này, chúng ta có một thành phần `HomeScreen` và muốn biết khi nào thành phần này được tập trung và khi nào không. Nếu thành phần được tập trung ban đầu và sau đó mất tập trung, thì log sẽ ghi lại hai dòng: 'HomeScreen is focused' (thành phần HomeScreen đang được tập trung) và 'HomeScreen is not focused' (thành phần HomeScreen không còn được tập trung). Điều này cho phép chúng ta theo dõi trạng thái tập trung của thành phần trong suốt quá trình chạy ứng dụng.
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ả 13 câu của chủ đề13 câu