preko96 / complete-mentions

MIT License
3 stars 7 forks source link

example with api call #10

Open efstathiosntonas opened 4 years ago

efstathiosntonas commented 4 years ago

Hi, can you please provide an example with an api call to fetch data? Thanks

marcosddourado commented 4 years ago

I did it like this:

const onKeywordChange = (keyword: string) => {
    setSuggestedMentions([]);
    requestAPI({
      params: `/mentions/nickname/${encodeURIComponent(keyword)}`,
      method: "GET"
    }).then(({ success, suggestions }) => {
      if (success) {
        setSuggestedMentions(suggestions);
      } else { throw "error"; }
    }).catch((error) => {
      console.log("getUsersByUserName error:", error);
    });
  };

Hope it helps you.