sickdyd / react-search-autocomplete

A search box that filters the provided array of objects
https://sickdyd.github.io/react-search-autocomplete
MIT License
216 stars 81 forks source link

RTK QUERY - UPDATE SEARCH RESULTS #98

Open gaizkaeu opened 1 year ago

gaizkaeu commented 1 year ago

Describe the bug I've followed the code sandbox from other issues I've seen. However I could't make it work. As It is explained I use a useState to store the data and update it.

Video https://www.youtube.com/watch?v=4heSS5SHSQA

Isn't shown in the video, but all the requests to the api returned the same data as the first one.

const [trigger] = useLazySearchUserQuery();

  const search_data: IUser[] = [];
  const [items, setItems] = React.useState(search_data);

  const handleOnSearch = (string) => {
    console.log("the search is debounced!");
    trigger({ first_name: string })
      .unwrap()
      .then((data) => {
        setItems(data);
      });
  };
          <ReactSearchAutocomplete
            items={items}
            onSearch={handleOnSearch}
            resultStringKeyName="first_name"
            onSelect={onSelect}
            inputDebounce={600}
            showIcon={false}
            fuseOptions={{ keys: ["first_name"] }}
            formatResult={formatResult}
          />

Screenshots

Screenshot 2022-12-07 at 19 58 46

Thanks!

vyombangwal commented 1 year ago

getting the same error, the items state is updated but it is not reflecting in suggestions

mhcifci commented 7 months ago

ive got same issue any fix?

a4ajay36 commented 6 months ago

I'm also facing the same issue guys, Does anybody get the solution?

orelkakon commented 2 weeks ago

Someone solve this? Please help :(