I have this function which get a JSON array from an URL containing list of options that I want to show as option in my Autocomplete
component.
function ShowMovies() {
async function GetMovies() {
movies_list = await fetch(url, {
method: 'GET',
headers: {
'Accept': 'application/json',
'authorization': token
},
}).then(response => movies_list = response.json());
}
GetMovies();
return ( <Autocomplete multiple freeSolo disablePortal id = 'movies'
name = 'movies'
options = {
movies_list
}
getOptionLabel = {
(option) => option.movie_name
}
renderInput = {
(params) => < TextField {
...params
}
label = 'New movies:' / >
}
/>
);
export default ShowMovies;
However, this fails to load returned options and gives me below warning. Which is according to my understanding is because at the time I am binding this to the component the fetch request is still ongoing.
Warning: Failed prop type: The prop `options` is marked as required in `ForwardRef(Autocomplete)`, but its value is `undefined`.
How can I delay this binding until the request is completed?