Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

60
ELI5: Why can't you pass props from a child component to a parent component?
Post Flair (click to view more posts with a particular flair)
Post Body

Ok so imagine we got some simple program that changes text in a parent based on a button press in the child

Parent.js:

const [displayText, setDisplayText] = useState("Button not clicked") 

export default function Parent(){
<View>
    <Text>{displayText}</Text>
    <Child />
</View>
}


Child.js:

export default function Child(){
    const [isClicked, setIsClicked] = useState(false)
    <View>
        <Button
        text="Click to change display text"
        onPress={() => {setIsClicked(true)}
        />
    </View>
}

In this example the parent needs to know the state of isClicked from the child component to change a value of the display text in the parent component. It seems the ethos of React is to build this sort of modular code where everything is in as small blocks as possible. But the information flow seems to really only want to go one way. I know you can technically pass a function from the child to the parent but it seems kinda hacky. Why isn't there like an offical streamlined way for a parent to be passed back up data from a child component so it can do something with that?

Author
Account Strength
80%
Account Age
2 years
Verified Email
Yes
Verified Flair
No
Total Karma
9,745
Link Karma
1,834
Comment Karma
7,565
Profile updated: 6 days ago
Posts updated: 4 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
1 year ago