This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ssr): hydrate client [PART-2] (#2537)
* feat(ssr): update usage of the API [PART-3]
- Loading branch information
Showing
12 changed files
with
408 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
InstantSearch, | ||
RefinementList, | ||
SearchBox, | ||
Hits, | ||
Configure, | ||
} from 'react-instantsearch-dom'; | ||
|
||
class App extends Component { | ||
static propTypes = { | ||
indexName: PropTypes.string.isRequired, | ||
searchClient: PropTypes.object.isRequired, | ||
searchState: PropTypes.object, | ||
resultsState: PropTypes.oneOfType([ | ||
PropTypes.arrayOf(PropTypes.object), | ||
PropTypes.object, | ||
]), | ||
}; | ||
|
||
static defaultProps = { | ||
searchState: {}, | ||
}; | ||
|
||
state = { | ||
searchState: this.props.searchState, | ||
}; | ||
|
||
onSearchStateChange = nextSearchState => | ||
this.setState({ searchState: nextSearchState }); | ||
|
||
render() { | ||
const { searchState } = this.state; | ||
|
||
return ( | ||
<InstantSearch | ||
{...this.props} | ||
searchState={searchState} | ||
onSearchStateChange={this.onSearchStateChange} | ||
> | ||
<Configure hitsPerPage={3} /> | ||
<SearchBox /> | ||
<RefinementList attribute="brand" /> | ||
<Hits /> | ||
</InstantSearch> | ||
); | ||
} | ||
} | ||
|
||
export default App; |
11 changes: 9 additions & 2 deletions
11
...rver-side-rendering/src/app/index.test.js → ...les/server-side-rendering/src/App.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
import { hydrate } from 'react-dom'; | ||
import { createApp } from './createApp'; | ||
|
||
const { App, props } = createApp(); | ||
|
||
const __APP_INITIAL_STATE__ = window.__APP_INITIAL_STATE__; | ||
|
||
delete window.__APP_INITIAL_STATE__; | ||
|
||
hydrate( | ||
<App {...props} {...__APP_INITIAL_STATE__} />, | ||
document.getElementById('root') | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import algoliasearch from 'algoliasearch/lite'; | ||
import App from './App'; | ||
|
||
export const createApp = () => { | ||
const indexName = 'instant_search'; | ||
const searchClient = algoliasearch( | ||
'latency', | ||
'6be0576ff61c053d5f9a3225e2a90f76' | ||
); | ||
|
||
const props = { | ||
indexName, | ||
searchClient, | ||
}; | ||
|
||
return { | ||
App, | ||
props, | ||
}; | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.