Creating Components
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. Serverless interfaces and procedures might differ from classic Elastic Stack deployments. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless
Generally available
Stack
Generally available
We provide a variety of Components out of the box. However, there might be cases where we do not have the Component you need.
In these cases, we recommend you use the low-level Search UI API to create these components yourself.
For a live example of this, check out this project on CodeSandbox.
To create your own component:
- Create a component.
- Import the
withSearchhigher order component in order to access Search UI’s actions and state. - Choose the actions and state you’ll need for this component in the first parameter to
withSearch. In the example below, they are using thefiltersstate and theclearFiltersaction. The full list of state and actions is avialable in the API documentation. - Pass your component as the second parameter with
withSearch, which will in turn pass the selected actions and state as props to your component. - Use the state and actions from props in your component.
import { withSearch } from "@elastic/react-search-ui";
function ClearFilters({ filters, clearFilters }) {
return (
<div>
<button onClick={() => clearFilters()}>
Clear {filters.length} Filters
</button>
</div>
);
}
export default withSearch(({ filters, clearFilters }) => ({
filters,
clearFilters
}))(ClearFilters);