Rewrote app to use hooks and fixed multiple re-renders.
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import React, { Component } from "react";
|
||||
import { Mutation, Query } from "react-apollo";
|
||||
import { GET_CURRENT_USER, SET_CURRENT_USER } from "../graphql/local.queries";
|
||||
|
||||
import App from "./App";
|
||||
import Spin from "../components/loading-spinner/loading-spinner.component";
|
||||
@@ -72,29 +70,17 @@ class AppContainer extends Component {
|
||||
}
|
||||
middlewares.push(authLink.concat(link));
|
||||
|
||||
const cache = new InMemoryCache({ addTypename: false });
|
||||
const cache = new InMemoryCache();
|
||||
|
||||
const client = new ApolloClient({
|
||||
link: ApolloLink.from(middlewares),
|
||||
cache,
|
||||
typeDefs,
|
||||
resolvers,
|
||||
defaultOptions: {
|
||||
watchQuery: {
|
||||
fetchPolicy: "cache-and-network",
|
||||
errorPolicy: "ignore"
|
||||
},
|
||||
query: {
|
||||
fetchPolicy: "cache-and-network",
|
||||
errorPolicy: "all"
|
||||
}
|
||||
}
|
||||
resolvers
|
||||
});
|
||||
|
||||
client.writeData({
|
||||
data: {
|
||||
...initialState
|
||||
}
|
||||
data: initialState
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -125,24 +111,7 @@ class AppContainer extends Component {
|
||||
|
||||
return (
|
||||
<ApolloProvider client={client}>
|
||||
<Query query={GET_CURRENT_USER}>
|
||||
{({ loading, error, data: { currentUser } }) => {
|
||||
if (loading) return <Spin />;
|
||||
if (error) return error.message;
|
||||
return (
|
||||
<Mutation mutation={SET_CURRENT_USER}>
|
||||
{setCurrentUser => (
|
||||
<App
|
||||
currentUser={currentUser}
|
||||
setCurrentUser={user => {
|
||||
setCurrentUser({ variables: { user } });
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</Mutation>
|
||||
);
|
||||
}}
|
||||
</Query>
|
||||
<App />
|
||||
</ApolloProvider>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user