diff --git a/types/react-frontload/index.d.ts b/types/react-frontload/index.d.ts new file mode 100644 index 0000000000..d8520347fa --- /dev/null +++ b/types/react-frontload/index.d.ts @@ -0,0 +1,31 @@ +// Type definitions for react-frontload 1.0 +// Project: https://github.com/davnicwil/react-frontload +// Definitions by: Anton Spirin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.1 + +import { ComponentClass, ComponentType } from 'react'; + +export interface FrontloadProps { + noServerRender?: boolean; +} + +export interface FrontloadConnectOptions { + noServerRender?: boolean; + onMount?: boolean; + onUpdate?: boolean; +} + +export const Frontload: ComponentClass; + +export function frontloadConnect

( + frontload: (props: P) => Promise, + options?: FrontloadConnectOptions, +):

(Component: ComponentType

) => ComponentType

; + +export function frontloadServerRender( + renderMarkup: (dryRun?: boolean) => string, + withLogging?: boolean, +): Promise; + +export as namespace ReactFrontload; diff --git a/types/react-frontload/react-frontload-tests.tsx b/types/react-frontload/react-frontload-tests.tsx new file mode 100644 index 0000000000..8359f25cb4 --- /dev/null +++ b/types/react-frontload/react-frontload-tests.tsx @@ -0,0 +1,42 @@ +import * as React from 'react'; +import * as ReactDOMServer from 'react-dom/server'; +import { frontloadConnect, frontloadServerRender, Frontload } from 'react-frontload'; + +interface MainProps { + testStringProp: string; +} + +class Main extends React.Component { + render() { + return

{this.props.testStringProp}
; + } +} + +const frontload = async (props: MainProps) => { + await new Promise(resolve => { + setTimeout(resolve, 1000); + }); +}; + +const FrontloadedMain = frontloadConnect( + frontload, + { noServerRender: false, onMount: false, onUpdate: false }, +)(Main); + +interface AppProps { + renderCase: string; +} + +const App = ({ renderCase }: AppProps) => { + return ( + +
+ + ); +}; + +(async () => { + const htmlString: string = await frontloadServerRender(dryRun => + ReactDOMServer.renderToString(), + ); +})(); diff --git a/types/react-frontload/tsconfig.json b/types/react-frontload/tsconfig.json new file mode 100644 index 0000000000..498866e175 --- /dev/null +++ b/types/react-frontload/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../", + "jsx": "react", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "react-frontload-tests.tsx" + ] +} diff --git a/types/react-frontload/tslint.json b/types/react-frontload/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/react-frontload/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}