This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
[Query component][Feature request]: Provide way to initialize local state with data #1862
Labels
feature
New addition or enhancement to existing solutions
I'm struggling to migrate code from the classic HoC-style to the Query component. I'm working on a basic form which shows a selection field of regions. In the old style I used componentWillReceiveProps to update my local state with an array with just the id of the first selectable item. This way, on initial loading, the first value was preselected.
As the new API is entirely in the render function (which should be pure), I'm not allowed to do any changes to the state (be it classic react state or redux/apollo-link-state). So the only option that I could find, would be to stack another component inside Query and use componentWillReceiveProps there, which seems like a lot of boilerplate for such a simple use-case.
Idea / Possible solution
If the Query-component would provide an onCompleted-callback, developers could use that function to do state-Changes which require knowledge of remote data.
<Query query={...} onCompleted={this.selectFirstElementInLocalState}> ... </Query>
But maybe there is another solution that I could not come up with?
Best regards!
Version
The text was updated successfully, but these errors were encountered: