Skip to content

Instantly share code, notes, and snippets.

@joeynimu
Last active May 10, 2018 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeynimu/f8adb510928fc8163aae9014e6b4abba to your computer and use it in GitHub Desktop.
Save joeynimu/f8adb510928fc8163aae9014e6b4abba to your computer and use it in GitHub Desktop.
urql-error
import React from 'react'
const Filters = () => {
// this throws the error yet on inspecting with react tools I can see teh data `prop` with `regions` on there
const regions = this.props.data.regions
return (<div>
<h3>Some data</h3>
<ul>{
regions && regions.map((d, i) => {
return <li key={d.region_id}>{d.region_name}</li>
})
}</ul>
</div>)
}
const areasQuery = `
query{
regions{
region_name
region_id areas{
area_id collection_centers {
collection_center_name
}
}
}
}
`
export default DataProvider(Filters, areasQuery)
import React, { Component } from 'react'
import { Provider, Client, query, Connect } from 'urql'
import { GRAPHQL_ENDPOINT } from '../constants'
const client = new Client({
url: GRAPHQL_ENDPOINT
})
const DataProvider = (WrappedComponent, q) => {
return class extends Component {
render () {
return (<Provider client={client}>
<Connect
query={query(q)}
children={({ loaded, fetching, refetch, data, error }) => {
return (<WrappedComponent data={data} {...this.props} />)
}}
/>
</Provider>)
}
}
}
export default DataProvider
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment