parent
9734f542d6
commit
d244c909be
@ -1,28 +1,35 @@ |
||||
import { AppContext } from '@remix-ui/app' |
||||
import React, { useContext } from 'react' |
||||
import { useEffect, useState } from 'react' |
||||
import React, { useContext, useEffect, useState } from 'react' |
||||
|
||||
interface IPluginViewWrapperProps { |
||||
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 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)}</> : <></>} |
||||
</> |
||||
) |
||||
} |
||||
|
Loading…
Reference in new issue