I want to pass a token stored in redux to the ApolloBoost Cliet. How do you acheive this using redux-react-hook library??
import ApolloBoost from 'apollo-boost'
const client = new ApolloBoost({
uri: 'https://api.github.com/graphql',
request: (operation) =>{
operation.setContext({
headers:{
Authorization: `bearer ${token}`
}
})
}
});
export default client
Edit: Tried below but failed
import {useCallback} from 'react'
import ApolloBoost from 'apollo-boost'
import {useMappedState} from 'redux-react-hook'
const client = new ApolloBoost({
uri: 'https://api.github.com/graphql',
request: (operation) =>{
const mapState = useCallback(state => state.token, [])
const token = useMappedState(mapState)
console.log(token)
operation.setContext({
headers:{
Authorization: `bearer ${token} `
}
})
}
});
export default client