Although the plugin already comes with a default UI interface, One can customize the UI/ UX according to their needs using the renderConfig object**.**
-
renderItem Function
It is a callback that accepts parameters, one of them is the suggestion item itself, utilize it to render a custom UI for every suggestion.
createSuggestionsPlugin(
...,
...,
{
renderItem: (props) => {
const { item, setQuery, refresh } = props;
if (item.type === "index") {
return (
<a
className="aa-item product-item"
href={item._source.url}
target="_blank"
rel="noreferrer"
>
<div className="product-image">
<img src={item._source.image} alt={item.value} />
</div>
<div className="product-details">
<h4>{item.value}</h4>
<p>{item._source.shortDescription}</p>
</div>
</a>
);
}
},
}
)
-
onItemSelect Function
It is a callback that accepts parameters(algolia control params), one of them is the setQuery
function, utilize it to customize the behavior of what happens when an individual suggestion item is clicked.
createSuggestionsPlugin(
...,
...,
{
renderItem: (props) => {
...
},
onItemSelect: (props) => {
const {
item: { url, label },
setQuery,
refresh
} = props;
if (url) {
setQuery(label);
window.open(url);
} else {
setQuery(label);
refresh();
}
},
}
)
-
renderHeader Function
It is a callback that accepts parameters(algolia params), one may utilize it to render a custom header before the suggestions.
createSuggestionsPlugin(
...,
...,
{
renderItem: (props) => {
...
},
onItemSelect: (props) => {
...
},
renderHeader: (props) => {
return (
<h4>
Products Listing <hr style={{ borderColor: "#d7d5f5" }} />
</h4>
);
},
}
)
-
renderFooter Function
It is a callback that accepts parameters(algolia params), one may utilize it to render a custom footer after the suggestions.
createSuggestionsPlugin(
...,
...,
{
renderItem: (props) => {
...
},
onItemSelect: (props) => {
...
},
renderHeader: (props) => {
...
},
renderFooter: (props) => {
return <hr style={{ borderColor: "#d7d5f5" }} />;
},
}
)
-
renderNoResults Function
It is a callback that accepts parameters(algolia params), one may utilize it to render a custom UI when no results are found.
createSuggestionsPlugin(
...,
...,
{
renderItem: (props) => {
...
},
onItemSelect: (props) => {
...
},
renderHeader: (props) => {
...
},
renderFooter: (props) => {
...
},
renderNoResults: (props) => {
if (props.state.query === "") {
return <p>Search for something to get direct product suggestions!</p>;
} else {
return <p>No products found! Try searching for something else!</p>;
}
}
}
)
-
useContextValue Boolean
When set to true, the context value is set with the following value:
{
total: ...,
time: ...,
resultsJson: ...
}
One can use this context value to display results stats.
createSuggestionsPlugin(
...,
...,
{
renderItem: (props) => {
...
},
onItemSelect: (props) => {
...
},
renderHeader: (props) => {
...
},
renderFooter: (props) => {
...
},
renderNoResults: (props) => {
if (props.state.query === "") {
return <p>Search for something to get direct product suggestions!</p>;
} else {
return <p>No products found! Try searching for something else!</p>;
}
},
useContextValue: true
}
)