State not working with custom component
See original GitHub issueThis issue is on iOS - not sure about Android.
1.0.137
I have the following simplified custom component, when I use it on a page the State doesn’t update:
class MyTestEntryState
{
public string? Text { get; set; }
public string? PlaceholderText { get; set; }
}
class MyTestEntry : Component<MyTestEntryState>
{
public MyTestEntry Text(string? text)
{
SetState(state => state.Text = text);
return this;
}
public MyTestEntry PlaceholderText(string? placeholderText)
{
SetState(state => state.PlaceholderText = placeholderText);
return this;
}
public override Entry Render() => new Entry()
.Text(State.Text ?? "")
.Placeholder(State.PlaceholderText ?? "");
}
Render method on any Component Page:
- Enter value in Source, see that the State updates in the “Destination” Entry.
- Uncomment the custom component.
- Enter value in Source, see that State stops updating - neither “Custom Destination” nor “Destination” updates.
public override VisualNode Render() => new ContentPage
{
new Grid("48, 48, 48", "*")
{
// new MyTestEntry()
// .PlaceholderText("Custom Destination")
// .Text(State.SearchText)
// .GridRow(0),
new Entry()
.Placeholder("Destination")
.Text(State.SearchText ?? "")
.GridRow(1),
new Entry()
.Placeholder("Source")
.Text(State.SearchText ?? "")
.OnTextChanged((s, e) => SetState(state => state.SearchText = e.NewTextValue))
.GridRow(2)
}
};
Issue Analytics
- State:
- Created 2 months ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
reactjs custom component input value doesnt update with ...
I am working on a list app, and I am having issues with the components not updating correctly. I pull the users list...
Read more >Component local state not updating with react custom hooks
Hi All, I'm just starting to use react hooks and I'm having some issues when using custom hooks. It's probably lack of understanding...
Read more >Custom component doesn't re-render an update state #38
I'm having hard time to update a props in a custom component and I finally though it's because I see it as a...
Read more >How To Manage State on React Class Components
Learning the concepts behind state management will help you navigate and troubleshoot class-based state management in existing code bases ...
Read more >Develop custom components
If Retool's built-in components don't work for your use case, you can build your own custom ... This allows the custom component to...
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 Free
Top 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

Hi, you can’t update the state like that (State is not yet ready at that moment). Try this instead:
BUT: from what I see you don’t need at all a stateful component, like this:
or even better, not using a Component, everything could be down to:
Why are you using a stateful component?
like this?