I am trying to pass a state that has been stored in useState hook in child component to the parent component which is the app.js i have create onPress event to pass the state to the prop that i have passed from the app,js, put when i press the function not working at all, here is the code
import React, { useState } from 'react';
import { Text, View, StyleSheet } from 'react-native';
import Constants from 'expo-constants';
import { TextInput } from 'react-native-paper';
import { RoundedButton } from '../../src/components/RoundedButton';
export function Focus({ addSubject }) {
const [title, setTitle] = useState(null);
return (
<View style={styles.container}>
<View style={styles.titleContainer}>
<Text style={styles.title}>what do you want to fucos on ? </Text>
<View style={styles.inputComtainer}>
<TextInput
style={styles.input}
onSubmitEditing={({ nativeEvent }) => {
setTitle(nativeEvent.text);
}}
/>
<RoundedButton
title="+"
size={60}
onPress={() => {
addSubject(title);
}}
/>
</View>
</View>
</View>
);
}
and this the the app.js code
import React, { useState } from 'react';
import { Text, View, StyleSheet } from 'react-native';
import Constants from 'expo-constants';
import { TextInput } from 'react-native-paper';
import { RoundedButton } from './src/components/RoundedButton';
import { Focus } from './src/features/Focus';
export default function App() {
const [focusSubject, setfocusSubject] = useState(null);
function reciveTitle(sendTitle) {
setfocusSubject(sendTitle);
}
return (
<View style={styles.container}>
{focusSubject ? (
<Text> {focusSubject}</Text>
) : (
<Focus addSubject={setfocusSubject} />
)}
</View>
);
}