File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react'
2
2
import { Switch , Route , Redirect } from 'react-router'
3
3
import { Link } from 'react-router-dom'
4
+ import { persistCache } from 'apollo-cache-persist'
4
5
5
6
import logo from '../logo.svg'
6
7
import StarCount from './StarCount'
@@ -10,6 +11,7 @@ import CurrentUser from './CurrentUser'
10
11
import Profile from './Profile'
11
12
import Reviews from './Reviews'
12
13
import CurrentTemperature from './CurrentTemperature'
14
+ import { cache } from '../lib/apollo'
13
15
14
16
const Book = ( { user } ) => (
15
17
< div >
@@ -21,8 +23,31 @@ const Book = ({ user }) => (
21
23
</ div >
22
24
)
23
25
26
+ const cacheHasBeenSaved = ! ! localStorage . getItem ( 'apollo-cache-persist' )
27
+
24
28
class App extends Component {
29
+ state = {
30
+ loading : cacheHasBeenSaved
31
+ }
32
+
33
+ async componentDidMount ( ) {
34
+ await persistCache ( {
35
+ cache,
36
+ storage : window . localStorage ,
37
+ maxSize : 4500000 , // little less than 5 MB
38
+ debug : true
39
+ } )
40
+
41
+ this . setState ( {
42
+ loading : false
43
+ } )
44
+ }
45
+
25
46
render ( ) {
47
+ if ( this . state . loading ) {
48
+ return null
49
+ }
50
+
26
51
return (
27
52
< div className = "App" >
28
53
< header className = "App-header" >
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ const networkLink = split(
50
50
authedHttpLink
51
51
)
52
52
53
- const cache = new InMemoryCache ( {
53
+ export const cache = new InMemoryCache ( {
54
54
cacheRedirects : {
55
55
Query : {
56
56
section : ( _ , { id } , { getCacheKey } ) =>
You can’t perform that action at this time.
0 commit comments