Luis Gestoso MuƱoz
01/09/2025, 10:17 AMrefinementList
components inside. When I click on the filters, they are applied to the search (I can see it both in the network tab because the calls are made and the url that is updated with routing
).
The problem is that when I close the modal, the filters are not applied anymore. The modal is not distroyed, it's just set to opacity-0
so the filters should still work. I also have SortBy
and RangeInput
in the modal and they work fine and are still applied after it's closed.
Investigation
I've been investigating and playing around and I've come to the conclussion that the root cause it's in transformItems
. If I don't use this property to change the displayed label then they work fine.
I've also tried moving the refinementList outside of the modal, and they also stop working when it's open even when they are outside (see the category filter in the video)
It looks like the problem is on the mapping of the `label`attribute of each element displayed, that somehow it is not able to keep the state of the component after any change.
Code
const transformCategories: RefinementListProps['transformItems'] = (items) => {
return items.map((item) => ({
...item,
label: brandIdToName[item.value] ?? 'Category',
}));
};
...
<RefinementList
attribute="categories"
limit={20}
sortBy={['count']}
classNames={{
count: 'hidden',
checkbox: 'hidden',
selectedItem: 'bg-black-100 text-primary-200',
list: 'flex flex-wrap gap-2',
item: 'rounded-xl border px-3 py-2 text-lg border-gray-400',
}}
transformItems={transformCategories}
/>
Request
Any idea on why this might be happening? Any thing that I should try but I haven't yet?Luis Gestoso MuƱoz
01/09/2025, 10:20 AMJason Bosco
01/09/2025, 5:18 PMFanis Tharropoulos
01/09/2025, 5:22 PMHayden Hoang
01/10/2025, 2:14 PMtransformCategories
function? Could you try declairing it outside of your React component?Luis Gestoso MuƱoz
01/10/2025, 3:46 PM