React Native 面试题与答案
问题 11. How do you handle navigation in React Native?
React Navigation is a popular library for handling navigation in React Native. It provides a navigation structure that allows developers to navigate between screens in a React Native app.
问题 12. What is the purpose of 'AsyncStorage' in React Native?
'AsyncStorage' is a simple, asynchronous, key-value storage system in React Native. It is used for storing small amounts of data persistently across app restarts.
Example:
import AsyncStorage from '@react-native-async-storage/async-storage';
AsyncStorage.setItem('key', 'value');
问题 13. What are Hooks in React Native?
Hooks are functions that allow developers to use state and other React features in functional components. Common hooks include useState and useEffect.
Example:
const [count, setCount] = useState(0);
useEffect(() => {
console.log('Component mounted!');
}, []);
问题 14. How can you optimize performance in a React Native app?
Performance optimization in React Native can be achieved by using PureComponent, memoization, optimizing renders, and using tools like React DevTools.
问题 15. What is the purpose of 'StyleSheet' in React Native?
'StyleSheet' is used to define styles in a React Native app. It provides an abstraction that enables better performance by allowing the framework to optimize the styling.
Example:
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
用户评价最有帮助的内容: