Hi guys! I have a question, but first I would like...
# community-help
l
Hi guys! I have a question, but first I would like to say that your product is amazing. Really easy to install, setup and your documentation is incredibly clear šŸ™ Now the question: The problem I'm using instant search with react to build the search frontend. I'm trying to build a filters modal with some
refinementList
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
Copy 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?
Video
j
This seems like a react specific thing... outside of Typesense. In any case, @Fanis Tharropoulos / @Hayden Hoang any pointers off the top of your head?
f
Could you link a reproducible example so we can take a deeper look? It's certainly not a Typesense issue, shouldn't even be an adapter issue for that matter, as it doesn't handle state
h
Hey @Luis Gestoso MuƱoz, where do you declare your
transformCategories
function? Could you try declairing it outside of your React component?
l
Wow @Hayden Hoang that worked! Thank you so much ty
šŸ™Œ 1