Function: useWebshell
â–¸ useWebshell<C, F>(__namedParameters: { features: F ; webViewRef: unknown ; webshellProps: WebshellProps<ComponentProps<C>, F> }): React_2.ComponentProps<C> & { ref: ElementRef<C> }
Inject features into a WebView, enabling capabilities such
as:
- handling messages from the Web environment;
- sending messages to the Web environment, see WebHandle;
- running script in the Web environment.
remarks
- You should always pass all props returned by this hook to the
WebViewcomponent, and never override any of those props. - If you need to pass props to the
WebView, use thepropsparameter field. - If you need to pass a reference to the
WebView, pass this reference to thewebViewRefparameter field.
example
import {
useWebshell,
HandleHashChangeFeature,
HandleVisualViewportFeature
} from '@formidable-webview/webshell';
const features = [
new HandleHashChangeFeature(),
new HandleVisualViewportFeature()
]
const MyCustomWebView = (props) => {
const webViewProps = useWebshell({ features, props });
return <WebView {...webViewProps} />;
}
Type parameters:
| Name | Type | Description |
|---|---|---|
C | ComponentType<any> | The type of the WebView component. |
F | Feature<{}, {}, {}>[] | The type for a collection of features to inject. |
Parameters:
| Name | Type |
|---|---|
__namedParameters | { features: F ; webViewRef: unknown ; webshellProps: WebshellProps<ComponentProps<C>, F> } |
Returns: React_2.ComponentProps<C> & { ref: ElementRef<C> }
Props for the WebView component.