Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/m19c/relay-context
A simple way to manage your relay environment(s)
https://github.com/m19c/relay-context
graphql react relay relay-modern
Last synced: 6 days ago
JSON representation
A simple way to manage your relay environment(s)
- Host: GitHub
- URL: https://github.com/m19c/relay-context
- Owner: m19c
- License: mit
- Created: 2017-06-21T14:32:59.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-09-27T12:27:54.000Z (about 7 years ago)
- Last Synced: 2024-11-03T13:05:17.965Z (14 days ago)
- Topics: graphql, react, relay, relay-modern
- Language: JavaScript
- Homepage:
- Size: 76.2 KB
- Stars: 10
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# relay-context
Relay's original `QueryRenderer` requires an environment to determine the graphql endpoint to talk with. Mostly you will do something like this:- pass down through props
- store in the window to access it later on
- store it in a registry object to access it later onThis is where `relay-context` comes into play. It provides a high-order component to register your environment(s) at one place (see Example > Main entry point). It is also possible to specify a default environment for your `QueryRenderer`.
## Install
### yarn
```
yarn add relay-context
```### npm
```
npm i --save relay-context
```## Example
### Main entry point
```javascript
import { Context } from 'relay-context';
import { render } from 'react-dom';
import App from './components/App';// create your relay environment(s)
const environmentA = new Environment();
const environmentB = new Environment();render(
)
```### Somewhere in your application (e.g. `Beer.js`)
```javascript
import React from 'react';
import { QueryRenderer } from 'relay-context'
import { graphql } from 'react-relay';export default ({ slug }) => {
// TODO: render stuff
}}
/>;
```