Skip to content

Instantly share code, notes, and snippets.

@damassi
Last active January 19, 2018 20:11
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 damassi/8bbcc8179a0a4d2513e254737420c1e1 to your computer and use it in GitHub Desktop.
Save damassi/8bbcc8179a0a4d2513e254737420c1e1 to your computer and use it in GitHub Desktop.
Stub Relay so that `react-relay` HOC components can accept raw data rather than using Relay network layer
render () {
const artwork = { name: 'Banksy' }
return (
<RelayStubProvider>
<Artwork artwork={artwork} />
</RelayStubProvider>
)
}
import PropTypes from 'prop-types'
import { Component } from 'react'
import { Environment, Network, RecordSource, Store } from 'relay-runtime'
export class RelayStubProvider extends Component {
static propTypes = {
children: PropTypes.node.isRequired,
relay: PropTypes.object
}
static defaultProps = {
relay: {
environment: new Environment({
network: Network.create(x => x),
store: new Store(new RecordSource())
}),
variables: {}
}
}
static childContextTypes = {
relay: PropTypes.object.isRequired
}
getChildContext () {
return {
relay: this.props.relay
}
}
render () {
return this.props.children
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment