The Complete React Native Hooks Course -

import React, useState from 'react'; import View, Text, Button, TextInput from 'react-native'; export default function UserInput() const [name, setName] = useState(''); const [submitted, setSubmitted] = useState(false);

return <Button title="Go back" onPress=() => navigation.goBack() />;

return ( <View> <Text>Count: state.count</Text> <Button title="+" onPress=() => dispatch( type: 'increment' ) /> <Button title="-" onPress=() => dispatch( type: 'decrement' ) /> </View> ); The Complete React Native Hooks Course

// 3. Consume in any child function ThemedComponent() const theme = React.useContext(ThemeContext); return <Text style= color: theme === 'dark' ? 'white' : 'black' >Hello</Text>;

if (loading) return <ActivityIndicator size="large" />; return ( <View> <Text>JSON.stringify(data)</Text> </View> ); import React, useState from 'react'; import View, Text,

State persists across re-renders; updating state triggers a re-render. 2. useEffect – Handling Side Effects Goal: Replace lifecycle methods ( componentDidMount , componentDidUpdate , componentWillUnmount ).

const fetchData = async () => try const res = await fetch(url, signal: abortController.signal ); if (!res.ok) throw new Error('Network error'); const json = await res.json(); setData(json); catch (err) if (err.name !== 'AbortError') setError(err.message); finally setLoading(false); ; try const res = await fetch(url

return ( <View> <TextInput placeholder="Enter your name" value=name onChangeText=setName style= borderWidth: 1, margin: 10, padding: 8 /> <Button title="Submit" onPress=() => setSubmitted(true) /> submitted && <Text>Hello, name!</Text> </View> );