Я добавил окно поиска. Я скрыл подробности API здесь. Продукты, выбранные и отображаемые на странице, теперь я создал одну панель поиска для фильтрации значения окна поиска на основе продуктов
Эта реакция поиска algolio
import React, { Component } from 'react'; import ReactDOM from
'react-dom'; import axios from "axios"; import { InstantSearch,
RefinementList } from 'react-instantsearch-dom';
import * as algoliasearch from "algoliasearch"; class App extends
React.Component {
constructor() {
super();
this.state = {
query:'',
data:{hits: []}
}
// set data to string instead of an array }
componentDidMount() {
this.getData(); } getData = () => {
var client = algoliasearch('id', 'api-key');
var index = client.initIndex('nameofindex');
index.search({
query: "",
attributesToRetrieve: ['ItemRate', 'Color','Category','productDetails','brandName','Price','productImages','objectID']
}, (error,data) => {
this.setState({
data: {
hits: data.hits
}
})
console.log(data.hits)
}) }
render() {
//const { data } = this.state;
const { query, data } = this.state;
return (
<div id="root" >
<center><h2> Products</h2></center>
<div className="search-books-input-wrapper">
</div>
<input
type="search"
/>
{
this.state.data.hits.map((data,index) => {
return<div>
<h3> Product Name: {data.productDetails}<br /></h3>
Product Brand: {data.brandName}<br />
Product Iteam: {data.ItemRate}<br />
Product Price: {data.Price}<br />
Product Category: {data.Category}<br />
Product image: {data.productImages}<br />
Product Color: {data.Color}<br />
Product ID: {data.objectID}<br />
</div>
})}
</div>
)
} }
//render(<App />, document.getElementById('app')); export default App;