Grokking React Native
0% completed
Differences Between State and Props
The number on a counter screen can be state in one component and a prop in another. Here, count is state in CounterScreen and arrives as a prop in CountLabel:
function CountLabel({ count }) { console.log('CountLabel rendered, count =', count); return <Text>Count: {count}</Text>; } function Title({ text }) { console.log('Title rendered'); return <Text>{text}</Text>; } function CounterScreen() { const [count, setCount] = useState(0); return ( <View> <Title text="My counter" /> <CountLabel count={count} />
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%