Home > Mobile >  React component SelectAsync
React component SelectAsync

Time:10-14

Have a SelectAsync component in React

<SelectAsync 
    cacheOptions
    defaultOptions
    loadOptions={loadDirectorList}
/>

and function to get the array from API

const loadDirectorList = (inputValue) => {
    return api.request('/api/director-list/' inputValue, 'GET')
                .then(res => res.data.json())
};

but on result I getting no options on SelectAsync

maybe someone knows where is my problem, will be so thanksfull, this response from API

{
"data": [
    {
        "uuid": "140b79ac-b294-4ede-9401-801c7c46f0b1",
        "first_name": "kdsc",
        "middle_name": null,
        "last_name": "mkldsklcdcmkl"
    },
    {
        "uuid": "de21abfe-ef59-434b-b5a9-0a0a620c45bc",
        "first_name": "director",
        "middle_name": null,
        "last_name": "director"
    },
    {
        "uuid": "d78c760a-c8a5-4e9a-809c-ba76c432d7e8",
        "first_name": "dilshod",
        "middle_name": null,
        "last_name": "ismoilzod"
    },
    {
        "uuid": "93493caf-6924-4bc5-a9b0-322de6f18ae4",
        "first_name": "drakula",
        "middle_name": null,
        "last_name": "feelin"
    },
    {
        "uuid": "9fab7fc6-57de-41e6-8c59-e51f265ade61",
        "first_name": "adam",
        "middle_name": null,
        "last_name": "white"
    }
],
"status": 200,
"statusText": "OK",
}

CodePudding user response:

loadDirectorList is a functional reference. It returns some thing like (){}. In order to get array you need to call it loadDirectorList().

Due to low explanation of your code, I think this must be causing problem.

CodePudding user response:

Solved with another way, just use simple Select and on event onInputChange call my function and set option state.

  • Related