I am currently developing a nice new UD component (release will be soon).
As I am not a React expert, not at all ;), can someone please help me or point me to a doc how to implement a invocation of a method within UD component.
something like reset(), …
I would like to invoke this method (optional using passed parameters and return the value to PS) using a PS script.
You’ll want to use the universal-dashboard npm package. For example, here’s the button. When you use withComponentFeatures, it will automatically hook up the event handlers and you can just call them like other JS functions. Take a look at handleClick. The onClick method accepts parameters. Those will be passed into the event handler as $Body and $EventData.
Thanks for the quick reply but I guess my request was a bit confusing or I dont understand your answer
I am not searching a way to invoke a PS script on a react event. Its the other way, I would like to invoke a react method using a PS command (e.g. Invoke-UDJavaScript).
We currently only have static handlers for sending state down. You’d have to use something like Set-UDElement in order to change state on the element but we don’t have a great way to call methods.
If you’re looking for a way to refresh a component, look at Sync-UDElement as well.
Wouldn’t this be a cool feature because i guess you are doing something similar with set/clear/…
Is there any way to invoke a react method if a props changes?
Because i am thinking about a props.method. props.methodparameters and props.methodreturn and invoke the react method if the props.method changes. In PS using tge Set-UDElement in order to invoke and afterwards Get-UDElement in order to get the return values.
I guess I have to work around some async in UD
Hope you can help me here because I am a React noob.
You can use the useEffect hook for something like this. The idea is that you can pass an array of props to the useEffect call and then it will call the effect when those props change.
Yo @augustin.ziegler sorry bit late to the party my new job is keeping me rather busy…you got a link to this component? Like I see @adam has provided help but just thinking if you could send the npm link more than happy to contribute