algolia / recommend

A UI library for Algolia Recommend, available for Vanilla JavaScript and React.
https://www.algolia.com/doc/ui-libraries/recommend/introduction/what-is-recommend/
MIT License
28 stars 11 forks source link

chore: update trending-facets types #163

Closed raed667 closed 10 months ago

raed667 commented 11 months ago

šŸ¤” What

Update trending-facets model types inherited from @algolia/recommend v4.22.0

https://github.com/algolia/algoliasearch-client-javascript/releases/tag/4.22.0

šŸ¤· Why

The trending-facets API only returns type string for facetValue.

All other models return items/hits which are of type RecordWithObjectID

However trending-facets model returns a list of TrendingFacetHit which (by definition) don't have an objectID property.

To simplify the code, we can remove the type argument TObject for trending-facets

šŸ” How to upgrade

If you're not using TypeScript, there is nothing to change. You can ignore the following.

If you're using TypeScript, and the trending-facets model, you should update your code like the following, by removing the type argument passed:

// The TrendingFacets React component usage goes from this:

type FacetHit = Hit<{
  facetName: string;
  facetValue: string;
}>
<TrendingFacets<FacetHit>
  indexName="my-index"
  // ...

// To this:
<TrendingFacets
  indexName="my-index"
  // ...

// or using hooks
const results = useTrendingFacets<FacetHit>(/* params */)
// becomes like this in v1.12.0
const results = useTrendingFacets(/* params */)

If you're using @algolia/recommend-js you can remove the FacetHit type in a similar way:


trendingFacets<FacetHit>({
  container: '#trendingFacets',
  indexName,
  // ...

// needs to be changed like this after v1.12.0: 
trendingFacets({
  container: '#trendingFacets',
  indexName,
  // ...

If you encounter an issue with the upgrade, open an issue referencing this release.