How to request a redraw on prop/state update?
See original GitHub issue- I have searched existing issues and this is not a duplicate
Issues and Steps to Reproduce
Give a component a prop which is created from a singleton object.
I.e. MyComponent.create(c).athing(MyData.instance()).build()
Which is then used to display some text,
@OnCreateLayout
static ComponentLayout onCreateLayout(
ComponentContext c,
@Prop MyData athing) {
return Column.create(c)
.child(create(c)
.text(athing.something)
...
And then in an onClick method update the singleton i.e:
MyData.instance().something = "NEW THING!";
Expected Behavior
The component should update the text with NEW THING
.
How can I update a prop - or whatever - which is passed to a component and have the component update? Or simple request a redraw of the component?
[Edit] Reading about it some more, the whole component must be recreated. This is fine. But in hierarchical components - say parent component and then a edit text component within it - how can I tell the parent from within the child to recreate itself? An event?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Prostate Cancer Nomograms
We treat every type of cancer, including the most important one: yours. With cancer, where you get treated first matters. From diagnosis to...
Read more >Prostate Cancer: Early Detection Guideline
The clinical guideline on Early Detection of Prostate Cancer discusses ... The completed evidence report may be requested through the AUA by ...
Read more >Prostate radiation - discharge - MedlinePlus
Skin Care · Wash gently with lukewarm water only. Do not scrub. Pat your skin dry. · Ask your provider what soaps, lotions,...
Read more >Prostate Enlargement (Benign Prostatic Hyperplasia) | NIDDK
Provides basic information about the prostate gland and prostate enlargement. Describes symptoms, diagnosis, and treatment.
Read more >Prostate biopsy - Mayo Clinic
A previous biopsy revealed prostate tissue cells that were abnormal but not cancerous. More Information. Prostate cancer · Request an ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @newfivefour , thanks for bringing this up. I’ll work on adding a concrete example on how to update the components in the tutorial.
In the meantime, regarding your question around these instructions: “If the props values must be updated, the parent has to create a new Component and pass down new values for the props”. Whenever you want to change the props for one of your components in your hierarchy, you need to create a new component using the new value of the prop and pass it as the new root for your
LithoView
using the setComponent method. The data flow model in Litho is top-down, meaning that whenever something has to change in a component, it’s the parent that is responsible for passing down that data to the children, and the only way to re-render the hierarchy is by setting a new root for the tree.If a component needs to keep track of an internal value that the parent doesn’t need to know about (for example the selected/unselected state of a toggle button), then you can use state updates to manage this value locally to the component. Each state update would trigger a new re-layout of the component tree.
Hope that helps, let me know if this is still unclear.
@newfivefour Did you ever figure this stuff out in a nice way? the state stuff is clear enough but doing a flux-like model update is not clear to me.