createWidgetComponent
The createWidgetComponent function can be used to create any type of component that extends from the ESRI Widget class. It takes in a function that creates the widget instance, a ref, and the widget properties, and returns a react-ready component that can be used as a child of a MapView.
Function signature
/**
* Factory function to create an esrieact widget component
* @param createWidget Function that takes in the widget properties
* (which must extend from __esri.WidgetProperties) and returns the widget instance
* @param ref The react ref to be passed from the parent
* @param properties The widget properties
* @returns A context provider whose context is the instance to be passed to children,
* or if there are no children, returns null.
*/
createWidgetComponent<P extends WidgetComponentProps>(
createWidget: CreateWidgetFunction,
ref: Ref<EsriWidget>,
{ children, events, position, view: viewFromProps, ...properties }: P,
) => JSX.Element | null;
Where
/**
* Properties that can be applied to any ESRIEACT Widget component. Extends from
* esri's WidgetProperties to include child components and the widget position
*/
export type WidgetComponentProps<
T extends __esri.WidgetProperties = __esri.WidgetProperties & {
view?: __esri.MapView;
},
E extends Record<string, Function> = {},
> = React.PropsWithChildren<T> & {
events?: E;
position?: string | __esri.UIAddPosition;
};
/**
* Function that takes in layer properties and returns an esri Layer instance. Properties must be
* any esri properties that extend esri.LayerProperties, and optional children
*/
export type CreateWidgetFunction<
T extends WidgetComponentProps = WidgetComponentProps,
> = (properties: T) => __esri.Widget;