Populate options when clicking the select element

My select options are obtained from third party API and there is a possibility that the API is taking too long to respond. Currently the options are populated right after the select element is mounted which took the loading so long. How can I populate the options when I click the select element?
8 Replies
Dan Harrin
Dan Harrin7mo ago
have you wrapped the options in a function ?
fikurimax
fikurimaxOP7mo ago
This is my options. Is this what you mean by wrapping in a function? the getPppProfile() function is calling a third party API
awcodes
awcodes7mo ago
You still need to return an array of key => value for the select. Right now you are returning a collection.
fikurimax
fikurimaxOP7mo ago
Thanks for the replies, but it still occurs
awcodes
awcodes7mo ago
Ok, what did you do to make it not a collection?
fikurimax
fikurimaxOP7mo ago
This is what the getPppProfile() function returns, and I changed the options like this
awcodes
awcodes7mo ago
Ok, but you’re picking and choosing what to share that you think is relevant and doesn’t give any of us a true insight to what could actually be the problem. And that’s ok, I get it. It could be proprietary code. Like, what is $profiles in the code you shared.
fikurimax
fikurimaxOP7mo ago
The $profiles var is an array, and it's obtained from a third party API above it. So the function getPppProfile() basically just calling an API and then return the response like this
$profiles = [
'Profile 1' => 'Profile 1',
'Profile 2' => 'Profile 2',
...
];
$profiles = [
'Profile 1' => 'Profile 1',
'Profile 2' => 'Profile 2',
...
];
The code is working though, the only problem is I want to make the select component calling the API to populate the options right after I click the component, not when its mounting
Want results from more Discord servers?
Add your server