Nutrient Web SDK

v0.0.0-dev

ReferenceUIInstanceGetter

Type Alias InstanceGetter

A callback function that returns a slot configuration. This provides a standard way to customize various slots.

The SDK internally calls this function as it prepares to render the associated component. Some slots can render before load() resolves, so call getInstance() when you need to use the public SDK instance. It returns null until the instance is available.

You can think of it as an initialization phase for the slot. It receives three parameters: getInstance, id, and helpers.

  • getInstance returns the latest Nutrient Web SDK instance, or null before the instance is available.
  • id is a unique identifier for the specific component being rendered into the slot. A component, such as comment thread, can have multiple instances, and the id helps to differentiate between them.
  • helpers is an object containing utilities for working with the slot at runtime. Today it exposes requestUpdate(), which asks the SDK to re-invoke render with the current params. See UI.SlotHelpers.
Type Alias
Type Signature
type InstanceGetter = () => NutrientViewer.Instance | null

Example

Customizing the comment thread slot with a callback function follows this pattern:

NutrientViewer.load({
// ... Your configuration.
ui: {
commentThread: (getInstance, id) => {
return {
render: (params) => {
const div = document.createElement("div");

// Return a DOM Node.
return div;
},
};
},
},
});

Trigger a manual rerender from an async callback:

NutrientViewer.load({
ui: {
tools: {
main: (getInstance, id, { requestUpdate }) => {
let label = "Loading…";
fetchToolbarLabel().then((value) => {
label = value;
requestUpdate();
});
return {
render: () => {
const div = document.createElement("div");
div.textContent = label;
return div;
},
};
},
},
},
});

See Also

Type Declaration

Returns