mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
fix(react): IonNav works with react (#25565)
Resolves #24002 Co-authored-by: Liam DeBeasi <liamdebeasi@icloud.com>
This commit is contained in:
38
packages/react/src/framework-delegate.tsx
Normal file
38
packages/react/src/framework-delegate.tsx
Normal file
@ -0,0 +1,38 @@
|
||||
import { FrameworkDelegate } from '@ionic/core/components';
|
||||
import { createPortal } from 'react-dom';
|
||||
|
||||
export const ReactDelegate = (
|
||||
addView: (view: React.ReactPortal) => void,
|
||||
removeView: (view: React.ReactPortal) => void
|
||||
): FrameworkDelegate => {
|
||||
let Component: React.ReactPortal;
|
||||
|
||||
const attachViewToDom = async (
|
||||
parentElement: HTMLElement,
|
||||
component: () => JSX.Element,
|
||||
propsOrDataObj?: any,
|
||||
cssClasses?: string[]
|
||||
): Promise<any> => {
|
||||
const div = document.createElement('div');
|
||||
cssClasses && div.classList.add(...cssClasses);
|
||||
parentElement.appendChild(div);
|
||||
|
||||
Component = createPortal(component(), div);
|
||||
|
||||
Component.props = propsOrDataObj;
|
||||
|
||||
addView(Component);
|
||||
|
||||
return Promise.resolve(div);
|
||||
};
|
||||
|
||||
const removeViewFromDom = (): Promise<void> => {
|
||||
Component && removeView(Component);
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
return {
|
||||
attachViewToDom,
|
||||
removeViewFromDom,
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user