mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 04:01:52 +00:00
[next] separate context objects for Document + fix tests
This commit is contained in:
Vendored
+13
@@ -1,4 +1,5 @@
|
||||
import * as React from "react";
|
||||
import { NextContext } from ".";
|
||||
|
||||
export interface DocumentProps {
|
||||
__NEXT_DATA__?: any;
|
||||
@@ -9,6 +10,18 @@ export interface DocumentProps {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Context object used inside `Document`
|
||||
*/
|
||||
export interface NextDocumentContext extends NextContext {
|
||||
/** A callback that executes the actual React rendering logic (synchronously) */
|
||||
renderPage(
|
||||
cb?: (enhancer: () => JSX.Element) => React.ComponentType<any>
|
||||
): {
|
||||
[key: string]: any
|
||||
};
|
||||
}
|
||||
|
||||
export class Head extends React.Component<any> {}
|
||||
export class Main extends React.Component {}
|
||||
export class NextScript extends React.Component {}
|
||||
|
||||
Vendored
-6
@@ -36,12 +36,6 @@ declare namespace next {
|
||||
jsonPageRes?: NodeResponse;
|
||||
/** Error object if any error is encountered during the rendering */
|
||||
err?: Error;
|
||||
/** a callback that executes the actual React rendering logic (synchronously) */
|
||||
renderPage(
|
||||
cb?: (enhancer: () => JSX.Element) => React.ComponentType<any>
|
||||
): {
|
||||
[key: string]: any
|
||||
};
|
||||
}
|
||||
|
||||
type NextSFC<P = {}> = NextStatelessComponent<P>;
|
||||
|
||||
@@ -1,12 +1,40 @@
|
||||
import Document, * as document from "next/document";
|
||||
import Document, { Head, Main, NextScript, NextDocumentContext } from 'next/document';
|
||||
import * as React from "react";
|
||||
|
||||
const results = (
|
||||
<Document any="property" should="work" here>
|
||||
<document.Head some="more" properties>
|
||||
<Head some="more" properties>
|
||||
<meta name="description" content="Head can have children, too!" />
|
||||
</document.Head>
|
||||
<document.Main />
|
||||
<document.NextScript />
|
||||
</Head>
|
||||
<Main />
|
||||
<NextScript />
|
||||
</Document>
|
||||
);
|
||||
|
||||
const Wrapper: React.SFC = ({ children }) => <React.Fragment>{children}</React.Fragment>;
|
||||
|
||||
export default class MyDocument extends Document {
|
||||
static async getInitialProps({ renderPage }: NextDocumentContext) {
|
||||
// Without callback
|
||||
const page = renderPage();
|
||||
// With callback
|
||||
const differentPage = renderPage(App => props => <Wrapper><App {...props} /></Wrapper>);
|
||||
const style = {};
|
||||
return { ...page, style };
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<html>
|
||||
<Head>
|
||||
<title>My page</title>
|
||||
<style id='cxs-style' dangerouslySetInnerHTML={{ __html: this.props.style }} />
|
||||
</Head>
|
||||
<body>
|
||||
<Main />
|
||||
<NextScript />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user