Skip to content

Instantly share code, notes, and snippets.

@JasonStoltz
Created January 28, 2019 21:50
Show Gist options
  • Save JasonStoltz/a19f241427f9daa9d866461df906845d to your computer and use it in GitHub Desktop.
Save JasonStoltz/a19f241427f9daa9d866461df906845d to your computer and use it in GitHub Desktop.
StickyFacets
<StickyFacets>
{({ facets }) => (
<React.Fragment>
<Facet
facets={facets}
field="date_established"
label="Date Established"
view={SingleRangeSelectFacet}
/>
<Facet
facets={facets}
field="states"
label="States"
view={MultiValueFacet}
/>
<Facet
facets={facets}
field="acres"
label="Acres"
view={SingleRangeSelectFacet}
/>
<Facet
facets={facets}
field="visitors"
label="Visitors"
view={MultiValueFacet}
/>
</React.Fragment>
)}
</StickyFacets>
import React from "react";
import { withSearch } from "@elastic/react-search-ui";
class StickyFacets extends React.Component {
constructor() {
super();
this.facetCache = {};
}
render() {
const { children, facets, resultSearchTerm } = this.props;
if (resultSearchTerm !== null && this.facetCache[resultSearchTerm]) {
return children({ facets: this.facetCache[resultSearchTerm] });
} else {
this.facetCache[resultSearchTerm] = facets;
return children({ facets: facets });
}
}
}
export default withSearch(StickyFacets);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment