relay-nextjs
Advanced tools
Comparing version 0.3.0 to 0.4.0
{ | ||
"name": "relay-nextjs", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Use Relay in your Next.js apps!", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
import type { NextPageContext, Redirect } from 'next'; | ||
import { NextRouter } from 'next/router'; | ||
import { ComponentType, ReactNode } from 'react'; | ||
import { PreloadedQuery } from 'react-relay/hooks'; | ||
import { Environment, GraphQLTaggedNode, OperationType, Variables } from 'relay-runtime'; | ||
export interface WiredOptions<ServerSideProps = {}> { | ||
import { Environment, GraphQLTaggedNode, OperationType } from 'relay-runtime'; | ||
export declare type WiredProps<P extends {} = {}, Q extends OperationType = OperationType> = P & { | ||
CSN: boolean; | ||
preloadedQuery: PreloadedQuery<Q>; | ||
}; | ||
export interface WiredOptions<Props extends WiredProps, ServerSideProps = {}> { | ||
/** Fallback rendered when the page suspends. */ | ||
fallback?: ReactNode; | ||
variablesFromContext?: (ctx: NextPageContext) => Variables; | ||
variablesFromContext?: (ctx: NextPageContext | NextRouter) => Props['preloadedQuery']['variables']; | ||
/** Called when creating a Relay environment on the client. Should be idempotent. */ | ||
@@ -22,7 +27,3 @@ createClientEnvironment: () => Environment; | ||
} | ||
export declare type WiredProps<P extends {} = {}, Q extends OperationType = OperationType> = P & { | ||
CSN: boolean; | ||
preloadedQuery: PreloadedQuery<Q>; | ||
}; | ||
export declare function Wire<Props extends WiredProps, ServerSideProps>(Component: ComponentType<Props>, query: GraphQLTaggedNode, opts: WiredOptions<ServerSideProps>): { | ||
export declare function Wire<Props extends WiredProps, ServerSideProps>(Component: ComponentType<Props>, query: GraphQLTaggedNode, opts: WiredOptions<Props, ServerSideProps>): { | ||
(props: Props): JSX.Element; | ||
@@ -29,0 +30,0 @@ getInitialProps: (ctx: NextPageContext) => Promise<{ |
@@ -51,4 +51,5 @@ "use strict"; | ||
react_1.useEffect(() => { | ||
loadQuery(router.query); | ||
}, [loadQuery, router.query]); | ||
var _a; | ||
loadQuery(((_a = opts.variablesFromContext) !== null && _a !== void 0 ? _a : defaultVariablesFromContext)(router)); | ||
}, [loadQuery, router]); | ||
if (props.CSN) { | ||
@@ -55,0 +56,0 @@ return (jsx_runtime_1.jsx(error_boundry_1.WiredErrorBoundry, { children: jsx_runtime_1.jsx(react_1.Suspense, Object.assign({ fallback: (_a = opts.fallback) !== null && _a !== void 0 ? _a : 'Loading...' }, { children: jsx_runtime_1.jsx(Component, Object.assign({}, props, { preloadedQuery: queryReference }), void 0) }), void 0) }, void 0)); |
28603
421