Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obtaining the mutateCallback() outside of the render function #43

Closed
serle opened this issue Aug 13, 2018 · 1 comment
Closed

Obtaining the mutateCallback() outside of the render function #43

serle opened this issue Aug 13, 2018 · 1 comment
Labels
project-apollo-client (legacy) LEGACY TAG DO NOT USE

Comments

@serle
Copy link

serle commented Aug 13, 2018

Description:

I have a centralized component that services other components in my application besides rendering its own UI (e.g. UndoManager). The render method of my centralized component renders and <Mutation/> with it UI rendered by the render prop. However I would like to have the ability to add the mutate callback to the central components state, so that I can add it to the components state and have it available for external calls from other components in my application.

I need to call setState() outside of the render function, otherwise react complains. I could just do a workaround by updating a variable on this or create a wrapper component reverting to the HOC approach, but a cleaner solution would be for the <Mutate/> component to provide onMount() and onUnMount() callbacks which are invoked on the underlying lifecycle event, so that I could setState in the proper place.

Proposed Solution:

add onMount((mutate) => this.setState(..)) and onUnMount(() => this.setState(..)) to <Mutation/>

Does not change current behavior

In general I think that Apollo team should see which callbacks on <Query/> and <Subscription/> could additionally be made accessible through onMount() and onUnMount() props.

@hwillson hwillson added the project-apollo-client (legacy) LEGACY TAG DO NOT USE label Sep 18, 2018
@jerelmiller
Copy link
Member

Hey there 👋

I'm doing a sweep of issues in this repo and came across this request. We will be deprecating the query components (including <Mutation />) in future major versions of the library in favor of hooks. Feel free to open a new feature request if you have suggestions on how to improve the hook-based API. Thanks!

@jerelmiller jerelmiller closed this as not planned Won't fix, can't repro, duplicate, stale Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project-apollo-client (legacy) LEGACY TAG DO NOT USE
Projects
None yet
Development

No branches or pull requests

3 participants