how to transfer values between redux and apollo-client ?
See original GitHub issueHi
looking at the example with-redux-and-apollo, I can’t figure out how to copy a store’s value to props such that it is passed to a child component performing a graphql query. Here’s my current approach. I would greatly appreciate any hint, since using { connect } + MapStateToProps approach from ‘react-redux’ cannot access the store.
./lib/store.js
import Immutable from 'immutable'
const initialState = Immutable.fromJS({
keyword: 'I want to query this sentence'
})
export default {
search: (state = initialState, { type, payload }) => {
switch (type) {
default:
return state
}
}
./page/search.js
import SearchResult from '../containers/SearchResult'
import withData from '../lib/withData'
import App from '../components/App'
export default withData((props) => (
<div>
<App>
<SearchResult keyword={'I DON'T KNOW HOW TO PASS REDUX-STATE HERE'}/>
</App>
</div>
))
./containers/SearchResult.js
import withData from '../lib/withData'
import { gql, graphql} from 'react-apollo';
import SearchResult from '../components/Search'
const search = gql`
query search($keyword: String!, $size: Int!) {
search(keyword: $keyword, size: $size){
title
}
}
`;
export default withData(graphql(search, {
options: ({ keyword }) => ({
variables: {
keyword: { keyword },
size: 10
}
}),
props: ({ data }) => ({ data })
})(SearchResult))
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Redux to Apollo: Data Access Patterns - Apollo GraphQL Blog
The readField API takes 2 parameters, first a fieldName to read from the cache and then the StoreObject or Reference to read it...
Read more >how to transfer values between redux and apollo-client ? #1964
Hi looking at the example with-redux-and-apollo, I can't figure out how to copy a store's value to props such that it is passed...
Read more >How to use Redux with Apollo Client and GraphQL in React
You would compose the Redux layer around the Apollo Client layer to pass the selected repositories from the React Redux mapStateToProps to your ......
Read more >How can I use redux and graphql with apollo client in the ...
import { FETCH_PRODUCTS, FETCH_PRODUCTS_FAIL, FETCH_PRODUCTS_SUCCESS } from "../types"; import {gql} from "apollo-boost"; const getProductsQuery ...
Read more >Move Over Redux: Apollo-Client as a State Management ...
You may have noticed this block of code in our App component. This simply alternates the value of setting based on its current...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@theednaffattack here is my quick code (not tested) that might help Note: the rest are the same as @timneutkens’s examples and you may have add your reducers and actions
@tsupol Thanks! Be careful though.
compose
is imported fromredux
, not fromreact-redux