parent
45025f0e6f
commit
624ac09b6b
@ -1,28 +1,35 @@ |
|||||||
import { AppContext } from '@remix-ui/app' |
import { AppContext } from '@remix-ui/app' |
||||||
import React, { useContext } from 'react' |
import React, { useContext, useEffect, useState } from 'react' |
||||||
import { useEffect, useState } from 'react' |
|
||||||
|
|
||||||
interface IPluginViewWrapperProps { |
interface IPluginViewWrapperProps { |
||||||
plugin: any |
plugin: any |
||||||
|
useAppContext?: boolean // Optional flag to decide whether to use AppContext
|
||||||
} |
} |
||||||
|
|
||||||
export const PluginViewWrapper = (props: IPluginViewWrapperProps) => { |
export const PluginViewWrapper = ({ plugin, useAppContext = false }: IPluginViewWrapperProps) => { |
||||||
const [state, setState] = useState<any>(null) |
const [state, setState] = useState<any>(null) |
||||||
const appContext = useContext(AppContext) |
const appContext = useAppContext ? useContext(AppContext) : null |
||||||
|
|
||||||
useEffect(() => { |
useEffect(() => { |
||||||
if (props.plugin.setDispatch) { |
if (plugin.setDispatch) { |
||||||
props.plugin.setDispatch(setState) |
plugin.setDispatch(setState) |
||||||
} |
} |
||||||
if (props.plugin.setAppStateDispatch) { |
if (useAppContext && appContext.appStateDispatch && plugin.setAppStateDispatch) { |
||||||
props.plugin.setAppStateDispatch(appContext.appStateDispatch) |
plugin.setAppStateDispatch(appContext.appStateDispatch) |
||||||
} |
} |
||||||
}, []) |
}, [plugin]) |
||||||
|
|
||||||
return <>{state ? <>{props.plugin.updateComponent( |
if (useAppContext && appContext && appContext.appState) { |
||||||
{ |
return ( |
||||||
...state, |
<> |
||||||
...appContext['appState'] |
{state ? <>{plugin.updateComponent(state, appContext.appState)}</> : <></>} |
||||||
})} |
</> |
||||||
</> : <></>}</> |
) |
||||||
|
} |
||||||
|
|
||||||
|
return ( |
||||||
|
<> |
||||||
|
{state ? <>{plugin.updateComponent(state)}</> : <></>} |
||||||
|
</> |
||||||
|
) |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue