State is local to a component and is used to manage data that changes over time, while props are used to pass data from a parent component to a child component.
Solution Code
React Native
-- Example Code --
import React, { useState } from "react";
import { View, Text, Button } from "react-native";
const ParentComponent = () => {
const [count, setCount] = useState(0);
return (
<View>
<ChildComponent count={count} />
<Button title="Increment" onPress={() => setCount(count + 1)} />
</View>
);
};
const ChildComponent = ({ count }) => {
return <Text>Count: {count}</Text>;
};
export default ParentComponent;
Explanation
This code demonstrates the difference between state and props.Guided Hints
{'hint': 'State is local to a component.'}
{'hint': 'Props are used to pass data to child components.'}