Functional React Components with Ignition SDK

I think I already know the answer to this question but is there any support for Functional React components inside the Module SDK? If not are there any plans to support this?

Yes, functional components can be used inside of the Module SDK. Many of the components offered in Perspective are built that way. You only need to create a reference to the functional component to pass into the class that you create that implements ComponentMeta:

const BarcodeScannerInput = (props: ComponentProps<BarcodeScannerInputProps>) => {
  ...
}

…and then inside of the meta class (this is no different than using class components):

...
getViewComponent(): PComponent {
    return BarcodeScannerInput;
}
...
3 Likes

One more followup questions - how do I go about exposing functional component state (from the useState() hook) as props? I’m assuming I use the “installReactions” method in the ComponentMeta?

I’m basically trying to write back to the perspective property tree whenever an item is “selected” by my component.

I dont particualry use a functional react, but the principal should be the same.

Item selection can be done done by triggereing an event or i suppose you can also set a property.
When i need to change a property i do this in the meta:
image

you can also trigger an event like this: (in the brackets{ } go all the params you want to expose to the event)
image

1 Like