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
have you wrapped the options in a function ?
This is my options. Is this what you mean by wrapping in a function?
the getPppProfile() function is calling a third party API
You still need to return an array of key => value for the select. Right now you are returning a collection.
Thanks for the replies, but it still occurs
Ok, what did you do to make it not a collection?
This is what the getPppProfile() function returns,
and I changed the options like this
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.
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
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