0

I am using AsyncSelect from react select. I want to figure out how to fetch data in my case. My first purspose is to get all titles of todos in the dropdown, but i can't figure out.

import AsyncSelect from "react-select/async";

const WithPromises = () => {
  const filterData = (inputValue) => {
    const serverData = fetch("https://jsonplaceholder.typicode.com/todos")
      .then((response) => response.json())
      .then((json) => {
        return json;
      });
    console.log(serverData);
    return serverData;
  };

  const promiseOptions = (inputValue) => {
    filterData(inputValue);
  };

  return (
    <AsyncSelect 
    cacheOptions 
    defaultOptions 
    loadOptions={promiseOptions} />
  );
};

export default WithPromises;

My question is, how to pupulate with titles from todos my dropdown when i will open for the first time?
demo: https://codesandbox.io/s/codesandboxer-example-forked-zsj6i?file=/example.js

Asking
  • 3,487
  • 11
  • 51
  • 106

0 Answers0