mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 23:10:29 +00:00
Added declarations for 'react-frontload
This commit is contained in:
Vendored
+31
@@ -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'} />),
|
||||
);
|
||||
})();
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user