A local QueryRenderer for Relay.
For querying local data without sending a request to the server (local state management).
Provides functionality (likely) found in the next build of relay:
https://github.com/facebook/relay/blob/master/packages/react-relay/ReactRelayLocalQueryRenderer.js.
Notice that the Relay compiler still requires you to include a server schema field in the query.
Using npm:
$ npm install --save react-relay-local-query-renderer
Using yarn:
$ yarn add react-relay-local-query-renderer
Then with a module bundler like webpack, use as you would anything else:
// Using ES6 Modules
import ReactRelayLocalQueryRenderer from "react-relay-local-query-renderer";
// using CommonJS modules
const ReactRelayLocalQueryRenderer = require("react-relay-local-query-renderer");
Used just like a regular QueryRenderer.
Unlike QueryRenderer
, LocalQueryRenderer
is able to return a snapshot on the initial render.
import LocalQueryRenderer from "react-relay-local-query-renderer";
import environment from "./Environment";
function MyApp({ children }) {
return (
<LocalQueryRenderer
variables={{}}
environment={environment}
query={graphql`
query AppQuery {
__typename
settings {
title
}
}
`}
render={({ props }) => {
return <div>{props.settings.title}</div>;
}}
/>
);
}
react-relay-local-query-renderer is built and maintained by babangsund.