-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
docs: fixup onResetStore docs, convert to hooks #10047
docs: fixup onResetStore docs, convert to hooks #10047
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this contribution! I noticed up the page (on line 49) we have another code sample which does use withApollo
export default withApollo(graphql(PROFILE_QUERY, {
props: ({ data: { loading, currentUser }, ownProps: { client }}) => ({
loading,
currentUser,
resetOnLogout: async () => client.resetStore(),
}),
})(Profile));
We can probably update that as well in this PR, did you want to make that change?
Thanks @jpvajda. I'm not super familiar with the export default function Profile() {
const { data, loading, client } = useQuery(PROFILE_QUERY);
return (
<ProfileDisplay
loading={loading}
currentUser={data?.currentUser}
resetOnLogout={async () => client.resetStore()}
/>
);
} |
@henryqdineen good question! I'll defer to the team on that one 😄 . cc @benjamn @hwillson @MrDoomBringer @alessbell |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @henryqdineen, I have some small suggestions but other than that this looks great!
@henryqdineen Not a blocking request, but it might be better to use something like this, purely because it could be a little easier for people to drop-in to existing code. function Profile() {
const { data, client } = useQuery(PROFILE_QUERY);
return (
<Fragment>
<p>Current user: {data?.currentUser}</p>
<button onClick={async ()=>client.resetStore()}>
Log out
</button>
</Fragment>
);
} All the best, |
Co-authored-by: Emmanuel S. <emmanuelssr@gmail.com>
LGTM! @henryqdineen I went ahead and committed an update to that first example for All the best, |
Found a couple issues with the existing
onResetStore
docscomponentDidUnmount
doesn't exists (componentWillUnmount
does though)this.state.reset
is alwaysfalse
and wasn't correctly being set@apollo/react-hoc
module fromreact-apollo
, which has not been mentioned if reading the docs in orderFor this PR I also migrated to hooks since the HOCs are deprecate. Let me know if you would prefer it to be fixed up but still use the HOC. Thanks!