Bacancy Technology
Bacancy Technology represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Rise™.
12+
Countries where we have happy customers
1050+
Agile enabled employees
06
World wide offices
12+
Years of Experience
05
Agile Coaches
14
Certified Scrum Masters
1000+
Clients projects
1458
Happy customers
Artificial Intelligence
Machine Learning
Salesforce
Microsoft
SAP
December 4, 2023
To update the parent state from a child component in React-Native, you can create a function in the parent component that updates the state. Then, pass this function to the child component as a prop. When the child component needs to update the parent state, it can call this prop function.
const Child = ({ onUpdate }) => { return ( <TouchableOpacity onPress={onUpdate.bind(this, "Child Data")}> <Text>{"Press here for update!"}</Text> </TouchableOpacity> ) } const Parent = () => { /** State */ const [data, setData] = useState() /** State Handler */ const onChildPress = (childData) => setData(childData) return ( <View> <Text>{`Parent data: ${data}`}</Text> <Child onUpdate={onChildPress} /> </View> ) }