CMS data (like any
Binary) needs to be loaded from the cloud service before it can be used. When rendering content inside a React component, all CMS data is loaded automatically using
Sometimes, however, you may want to access CMS data outside of rendering, for example inside an event handler like
onClick. This is where
Scrivito.load comes in: It loads CMS data and allows you to work asynchronously with the loaded data.
If you wrap a function with
Scrivito.load, you will get a
Promise back. The Promise allows you to attach callbacks.
Scrivito.load executes the passed-in function and loads all the required data. Once all data has been loaded, the attached callbacks are run. The value returned by your function is forwarded to the callbacks.
Here is a simple example: