Home App Docs Github

Setting state using @builder.io/react?


Is it possible to set state using @builder.io/react ?


Thanks for the Q @cjl!

You absolutely can - using the data prop of the BuilderComponent React component.

Anything you pass there will be available on state in the Builder content.

You can pass any data, including functions, nested data, etc down, e.g:

    products: productsList,
    myFunction: () => alert('Triggered!'),
    foo: 'bar'
  }} />

And them use them in Builder.io content as

state.products, state.myFunction() etc

You can see more examples of that in this guide, more about the Readk SDK API here and more about binding that data to the UIs over here (binding data passed down works the same as data you connect via a URL)

Hope this helps and let us know if we can elaborate on anything here or answer any followup questions of yours about this!