mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add server.d.ts to react-instantsearch
This commit is contained in:
parent
e31b168ef1
commit
e3e00a62c2
@ -204,12 +204,62 @@ import { Hit, connectRefinementList, connectMenu } from 'react-instantsearch-cor
|
||||
|
||||
<RefinementList attribute="products" searchable />;
|
||||
|
||||
// https://community.algolia.com/react-instantsearch/guide/Search_parameters.html
|
||||
<InstantSearch
|
||||
appId="appId"
|
||||
apiKey="apiKey"
|
||||
indexName="indexName"
|
||||
>
|
||||
<Configure distinct={1}/>
|
||||
// widgets
|
||||
</InstantSearch>;
|
||||
() => {
|
||||
// https://community.algolia.com/react-instantsearch/guide/Search_parameters.html
|
||||
<InstantSearch
|
||||
appId="appId"
|
||||
apiKey="apiKey"
|
||||
indexName="indexName"
|
||||
>
|
||||
<Configure distinct={1}/>
|
||||
// widgets
|
||||
</InstantSearch>;
|
||||
};
|
||||
|
||||
import { createInstantSearch } from 'react-instantsearch-dom/server';
|
||||
// import { createServer } from 'http';
|
||||
declare function createServer(handler: (req: any, res: any) => any): any;
|
||||
import { renderToString } from 'react-dom/server';
|
||||
|
||||
() => {
|
||||
// https://community.algolia.com/react-instantsearch/guide/Server-side_rendering.html
|
||||
|
||||
// Now we create a dedicated `InstantSearch` component
|
||||
const { InstantSearch, findResultsState } = createInstantSearch();
|
||||
|
||||
class App extends React.Component<any> {
|
||||
render() {
|
||||
return (
|
||||
<InstantSearch
|
||||
appId="appId"
|
||||
apiKey="apiKey"
|
||||
indexName="indexName"
|
||||
searchState={this.props.searchState}
|
||||
resultsState={this.props.resultsState}
|
||||
>
|
||||
<SearchBox />
|
||||
<Hits />
|
||||
</InstantSearch>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const server = createServer(async (req, res) => {
|
||||
const searchState = {query: 'chair'};
|
||||
const resultsState = await findResultsState(App, {searchState});
|
||||
const appInitialState = {searchState, resultsState};
|
||||
const appAsString = renderToString(<App {...appInitialState} />);
|
||||
res.send(
|
||||
`
|
||||
<!doctype html>
|
||||
<html>
|
||||
<body>
|
||||
<h1>Awesome server-side rendered search</h1>
|
||||
<did id="root">${appAsString}</div>
|
||||
<script>window.__APP_INITIAL_STATE__ = ${JSON.stringify(appInitialState)}</script>
|
||||
<script src="bundle.js"></script> <!-- this is the build of browser.js -->
|
||||
</body>
|
||||
</html>`
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
14
types/react-instantsearch-dom/server.d.ts
vendored
Normal file
14
types/react-instantsearch-dom/server.d.ts
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
import * as React from 'react';
|
||||
|
||||
/**
|
||||
* Creates a specialized root InstantSearch component. It accepts
|
||||
* an algolia client and a specification of the root Element.
|
||||
* @param defaultAlgoliaClient - a function that builds an Algolia client
|
||||
* @returns an InstantSearch root
|
||||
*/
|
||||
export function createInstantSearch(
|
||||
defaultAlgoliaClient?: (appId: string, apiKey: string, options: { _useRequestCache: boolean }) => object
|
||||
): {
|
||||
InstantSearch: React.ComponentClass<any>;
|
||||
findResultsState(App: React.ComponentType<any>, props: any): Promise<any>
|
||||
};
|
||||
1
types/react-instantsearch/server.d.ts
vendored
Normal file
1
types/react-instantsearch/server.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
export { createInstantSearch } from 'react-instantsearch-dom/server';
|
||||
Loading…
Reference in New Issue
Block a user