WebViewer exposes an API to render custom elements in the UI. The Custom Element component accepts a render
function, which returns either a React element or an HTML element.
If your render returns a React component you may find that it does not update when its props change. Here is an example:
In the above example, anytime the state props text
and borderColor
change it will not trigger a re-render of your custom component.
The reason for this is that WebViewer renders your component as it was initially passed, and it will not update if its props change. If your UI requires this particular workflow you have several options.
The first is to consider if a custom element is the best fit for your use case. WebViewer also exposes a Stateful Button and a Custom Button that could achieve what you want.
Alternatively, you can structure your custom component to update each time the props change.
Here is a full example that shows how this could look in your React app.
The example above has a custom element that updates anytime the component's dependencies change. We achieve this by forcing a re-render of the custom element inside of a useEffect
, where we re-insert it to the UI. Notice the dependency array of that hook has the two props, which is what triggers the re-render anytime they change.
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales