내 GraphQL 서버의 데이터를 내 기본 애플리케이션에 반입하기 위해 react-apollo을 통합했습니다. 나는 redux 상점을 지속하고 rehydrating를 위해 redux-perist를 사용합니다.아폴로와 redux-persist
하지만 아폴로 상태를 재수 할 줄 모르겠습니다.
누구든지 어떻게 할 수 있는지 알고 있습니까?
감사
내 GraphQL 서버의 데이터를 내 기본 애플리케이션에 반입하기 위해 react-apollo을 통합했습니다. 나는 redux 상점을 지속하고 rehydrating를 위해 redux-perist를 사용합니다.아폴로와 redux-persist
하지만 아폴로 상태를 재수 할 줄 모르겠습니다.
누구든지 어떻게 할 수 있는지 알고 있습니까?
감사
당신은 redux-persist
의 autoRehydrate
기능을 사용할 수 있습니다. 그것은 당신이 블랙리스트에 올 때까지 asyncronously 모든 상점을 rehydrate 유형 REHYDRATE
유형의 작업을 실행합니다.
이전에 실행 된 쿼리를 실행하려고하면 Apollo가 Redux 저장소를 먼저 확인하고 APOLLO_QUERY_RESULT_CLIENT
작업 (서버를 쿼리하는 대신 클라이언트 저장소에서 반환 됨)을 실행해야합니다. 쿼리 (등, 첫째, 전용 캐시를 네트워크)의 데이터를 가져 오는 방법 당신은
가 여기에 기본 설정의 지정 fetchPolicy
을 수정할 수 있습니다 srtucker22 @
import React, { Component } from 'react';
import { ApolloProvider } from 'react-apollo';
import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
import ApolloClient, { createNetworkInterface } from 'apollo-client';
import { persistStore, autoRehydrate } from 'redux-persist';
import { AsyncStorage } from 'react-native';
const networkInterface = createNetworkInterface({ uri: 'http://localhost:8080/graphql' });
export const client = new ApolloClient({
networkInterface: networkInterface,
});
const store = createStore(
combineReducers({
apollo: client.reducer(),
}),
{}, // initial state
compose(
applyMiddleware(client.middleware()),
autoRehydrate(),
),
);
// persistent storage
persistStore(store, {
storage: AsyncStorage, // or whatever storage you want
});
export default class App extends Component {
render() {
return (
<ApolloProvider store={store} client={client}>
<YourApp />
</ApolloProvider>
);
}
}
감사합니다! 내 문제는 devTools()를 사용하고 autoRehydrate()를 사용했다는 것입니다. 이상한 이유로이 방법이 작동하지 않습니다. 먼저 autoRehydrate()를 먼저 실행 한 다음 devTools()를 실행해야합니다. 이제 작동합니다! – Carol
@ 캐롤 당신을 축복합니다. 당신의 솔루션은 방금 3 일간의 손톱 물기와 머리카락을 끝까지 가져 왔습니다. '(typeof window .__ REDUX_DEVTOOLS_EXTENSION__! == 'undefined'|| process.env.NODE_ENV! == 'production') 전에 autoRehydrate() page .__ REDUX_DEVTOOLS_EXTENSION __() : (f) => f,'페이지 재로드 후 해석 된 데이터가 유지됩니다. – TheoG