How to populate a react custom component input field from api response?

Hey all, for a custom component input field is there a way to make an api request to populate an enum or list?

For example currently I have a string field but I want the content author to select from a list of items based on the response of the api request.

Thanks

Hi! Absolutely - you can do this in your application’s code when you register the custom component. For example, if you were fetching categories from your API, it would look something like this in your builder-registry.ts :

fetch("YOUR_API_URL").then(res => res.json()).then((data) => {
  const categories = data.results.map((category: any) => category.data.name)
  
  Builder.registerComponent(BlogCategory, {
    name: "BlogCategory",
    image: 'https://cdn.builder.io/api/v1/image/assets%2FagZ9n5CUKRfbL9t6CaJOyVSK4Es2%2Ffab6c1fd3fe542408cbdec078bca7f35',
    inputs: [{
      name: "category",
      type: "string",
      enum: categories,
    }]
  });        
});

This is a starting point, and you would want to make sure to handle failures from the API gracefully to ensure the component is registered, but I hope this helps.