mirror of
https://github.com/kusti8/proton-native.git
synced 2026-05-15 14:15:50 -06:00
[GH-ISSUE #268] State Not Propagating to Child Components #181
Labels
No labels
bug
documentation
enhancement
libui issue
pull-request
question
wait for libui implementation
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/proton-native#181
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jcolag on GitHub (Feb 25, 2020).
Original GitHub issue: https://github.com/kusti8/proton-native/issues/268
Describe the bug
When updating the
stateof a parent component, the change does not flow back to the child.To Reproduce
Here's a stripped down example, with just a button to trigger a change in the parent (via a callback), which should update its (other) child.
Expected behavior
In the sample code above, the
Textcomponent (inClickTotal) should increment on every button click. Instead, we can see thatExamplere-renders and reportsthis.state.countas increasing, butClickTotalalways sees thecountas zero.Edit to clarify: The child component re-renders when the parent state changes, but always sees the property as its original value, rather than what's being passed in.
Screenshots
Hopefully not necessary, but I can add them later.
Versions:
Additional context
I could obviously add Reflux to the project, but that seems like overkill for such minimal data requirements, if it's not absolutely necessary. The actual project I'm working on is going to need to pass around lists of objects, but the same applies.
Also, v2 is a massive improvement over v1. Thanks!
@kusti8 commented on GitHub (Mar 16, 2020):
This is because in your
ClickTotalconstructor, you are setting the count into the state ofClickTotal. This is just a number, it has no reference to the other count, so it doesn't get updated. In general, it is better practice to not set your props into the state, but instead just reference them fromthis. Here's the fixed example:@jcolag commented on GitHub (Mar 17, 2020):
Ah, thanks! I was hoping this was me doing something stupid.