|
1 | 1 | import { DjangoFormProps, HttpRequestProps } from "./types";
|
2 |
| -import React from "preact/compat"; |
3 |
| -import ReactDOM from "preact/compat"; |
| 2 | +import { useEffect } from "preact/hooks"; |
| 3 | +import { render, createElement } from "preact"; |
4 | 4 | /**
|
5 | 5 | * Interface used to bind a ReactPy node to React.
|
6 | 6 | */
|
7 | 7 | export function bind(node) {
|
8 | 8 | return {
|
9 |
| - create: (type, props, children) => |
10 |
| - React.createElement(type, props, ...children), |
| 9 | + create: (type, props, children) => createElement(type, props, ...children), |
11 | 10 | render: (element) => {
|
12 |
| - ReactDOM.render(element, node); |
| 11 | + render(element, node); |
13 | 12 | },
|
14 |
| - unmount: () => ReactDOM.unmountComponentAtNode(node), |
| 13 | + unmount: () => render(null, node), |
15 | 14 | };
|
16 | 15 | }
|
17 | 16 |
|
18 | 17 | export function DjangoForm({
|
19 | 18 | onSubmitCallback,
|
20 | 19 | formId,
|
21 | 20 | }: DjangoFormProps): null {
|
22 |
| - React.useEffect(() => { |
| 21 | + useEffect(() => { |
23 | 22 | const form = document.getElementById(formId) as HTMLFormElement;
|
24 | 23 |
|
25 | 24 | // Submission event function
|
@@ -64,7 +63,7 @@ export function DjangoForm({
|
64 | 63 | }
|
65 | 64 |
|
66 | 65 | export function HttpRequest({ method, url, body, callback }: HttpRequestProps) {
|
67 |
| - React.useEffect(() => { |
| 66 | + useEffect(() => { |
68 | 67 | fetch(url, {
|
69 | 68 | method: method,
|
70 | 69 | body: body,
|
|
0 commit comments