Added declarations for 'react-frontload

This commit is contained in:
Anton Spirin
2018-12-22 22:15:58 +02:00
parent a1b863c972
commit 2ee90459c2
4 changed files with 101 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
// Type definitions for react-frontload 1.0
// Project: https://github.com/davnicwil/react-frontload
// Definitions by: Anton Spirin <https://github.com/rockon404>
// 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<FrontloadProps>;
export function frontloadConnect <P = {}>(
frontload: (props: P) => Promise<void>,
options?: FrontloadConnectOptions,
): <P = {}>(Component: ComponentType<P>) => ComponentType<P>;
export function frontloadServerRender(
renderMarkup: (dryRun?: boolean) => string,
withLogging?: boolean,
): Promise<string>;
export as namespace ReactFrontload;
@@ -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<MainProps> {
render() {
return <div>{this.props.testStringProp}</div>;
}
}
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 (
<Frontload noServerRender={false}>
<Main testStringProp={'Hello, World!'} />
</Frontload>
);
};
(async () => {
const htmlString: string = await frontloadServerRender(dryRun =>
ReactDOMServer.renderToString(<App renderCase={dryRun ? 'Dry run true case' : 'Dry run false case'} />),
);
})();
+25
View File
@@ -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"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}