{
+export const PluginViewWrapper = ({ plugin, useAppContext = false }: IPluginViewWrapperProps) => {
const [state, setState] = useState
(null)
- const appContext = useContext(AppContext)
+ const appContext = useAppContext ? useContext(AppContext) : null
useEffect(() => {
- if (props.plugin.setDispatch) {
- props.plugin.setDispatch(setState)
+ if (plugin.setDispatch) {
+ plugin.setDispatch(setState)
}
- if (props.plugin.setAppStateDispatch) {
- props.plugin.setAppStateDispatch(appContext.appStateDispatch)
+ if (useAppContext && appContext.appStateDispatch && plugin.setAppStateDispatch) {
+ plugin.setAppStateDispatch(appContext.appStateDispatch)
}
- }, [])
+ }, [plugin])
- return <>{state ? <>{props.plugin.updateComponent(
- {
- ...state,
- ...appContext['appState']
- })}
- > : <>>}>
+ if (useAppContext && appContext && appContext.appState) {
+ return (
+ <>
+ {state ? <>{plugin.updateComponent(state, appContext.appState)}> : <>>}
+ >
+ )
+ }
+
+ return (
+ <>
+ {state ? <>{plugin.updateComponent(state)}> : <>>}
+ >
+ )
}