mirror of
https://github.com/zadam/trilium.git
synced 2025-11-06 05:15:59 +01:00
feat(react): set up hook for reacting to events
This commit is contained in:
21
apps/client/src/widgets/react/ReactBasicWidget.tsx
Normal file
21
apps/client/src/widgets/react/ReactBasicWidget.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import { createContext, JSX, render } from "preact";
|
||||
import BasicWidget from "../basic_widget.js";
|
||||
import Component from "../../components/component.js";
|
||||
|
||||
export const ParentComponent = createContext<Component | null>(null);
|
||||
|
||||
export default abstract class ReactBasicWidget extends BasicWidget {
|
||||
|
||||
abstract get component(): JSX.Element;
|
||||
|
||||
doRender() {
|
||||
const renderContainer = new DocumentFragment();
|
||||
render((
|
||||
<ParentComponent.Provider value={this}>
|
||||
{this.component}
|
||||
</ParentComponent.Provider>
|
||||
), renderContainer);
|
||||
this.$widget = $(renderContainer.firstChild as HTMLElement);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user