Custom component - send event into component

I'm building a custom component in retool (with regards to this Retools JSON editor w/ completions from a JSON schema), and am looking to someway to trigger an event inside the component.

For triggering an event in the outside world I can use the triggerQuery mechanism. However, if I need to notify my component that something changed in the outside world - how can I do that? The model allows me to propagate values (especially initial values), but I haven't found anything that allows me to communicate an event

Hi @yassa! What kind of event are you hoping to look for in the outside world? I wonder if we can somehow still use the model (e.g. with the outside world event, set a temp state and have the model subscribed to that temp state value so it forces an update when the temp state value updates).

Hey, so for example, I built a custom component wrapping the Monaco code editor. The component gets an initial value (easy via the model), outputs the current value the user modified within it (easy via the model & modelUpdate), and notifies the outside world when that value changed (easy via triggerQuery).

But, say I have a quick-action button outside this component, that forces some modification of the current value in the editor. Changing the initial value on the model does nothing (as the code editor had already initiated), unless I reload the entire component which is cumbersome. What I want is something the component gets in its parameters, that I can listen to, and call an internal method when it happens (the opposite or triggerQuery).

What I ended up doing is having a "valueOverride" property on my model. I track changes to that property with useEffect, useRef in the component, and once a change is detected, I call my inner function to deal with it.
It's 20 lines of cumbersome code I've love to replace with a single line of registering to an incoming event.

Hey @yassa! What you have setup sounds like a good workaround to me.

Though as a quick thought, if you trigger an event handler to change a temp state value (for example) and reference that temp state value in your custom component's model, it should also work similarly! Perhaps with less code.

Let me know if this sounds helpful at all!