Last active
May 10, 2018 15:25
-
-
Save joeynimu/f8adb510928fc8163aae9014e6b4abba to your computer and use it in GitHub Desktop.
urql-error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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