@@ -2,21 +2,6 @@ import { ReactPyDjangoClient } from "./client";
2
2
import React from "react" ;
3
3
import ReactDOM from "react-dom" ;
4
4
import { Layout } from "@reactpy/client/src/components" ;
5
- import { DjangoFormProps } from "./types" ;
6
-
7
- /**
8
- * Interface used to bind a ReactPy node to React.
9
- */
10
- export function bind ( node ) {
11
- return {
12
- create : ( type , props , children ) =>
13
- React . createElement ( type , props , ...children ) ,
14
- render : ( element ) => {
15
- ReactDOM . render ( element , node ) ;
16
- } ,
17
- unmount : ( ) => ReactDOM . unmountComponentAtNode ( node ) ,
18
- } ;
19
- }
20
5
21
6
export function mountComponent (
22
7
mountElement : HTMLElement ,
@@ -84,7 +69,7 @@ export function mountComponent(
84
69
// Replace the prerender element with the real element on the first layout update
85
70
if ( client . prerenderElement ) {
86
71
client . onMessage ( "layout-update" , ( { path, model } ) => {
87
- if ( client . prerenderElement ) {
72
+ if ( client . prerenderElement && client . mountElement ) {
88
73
client . prerenderElement . replaceWith ( client . mountElement ) ;
89
74
client . prerenderElement = null ;
90
75
}
@@ -94,51 +79,3 @@ export function mountComponent(
94
79
// Start rendering the component
95
80
ReactDOM . render ( < Layout client = { client } /> , client . mountElement ) ;
96
81
}
97
-
98
- export function DjangoForm ( {
99
- onSubmitCallback,
100
- formId,
101
- } : DjangoFormProps ) : null {
102
- React . useEffect ( ( ) => {
103
- const form = document . getElementById ( formId ) as HTMLFormElement ;
104
-
105
- // Submission event function
106
- const onSubmitEvent = ( event ) => {
107
- event . preventDefault ( ) ;
108
- const formData = new FormData ( form ) ;
109
-
110
- // Convert the FormData object to a plain object by iterating through it
111
- // If duplicate keys are present, convert the value into an array of values
112
- const entries = formData . entries ( ) ;
113
- const formDataArray = Array . from ( entries ) ;
114
- const formDataObject = formDataArray . reduce ( ( acc , [ key , value ] ) => {
115
- if ( acc [ key ] ) {
116
- if ( Array . isArray ( acc [ key ] ) ) {
117
- acc [ key ] . push ( value ) ;
118
- } else {
119
- acc [ key ] = [ acc [ key ] , value ] ;
120
- }
121
- } else {
122
- acc [ key ] = value ;
123
- }
124
- return acc ;
125
- } , { } ) ;
126
-
127
- onSubmitCallback ( formDataObject ) ;
128
- } ;
129
-
130
- // Bind the event listener
131
- if ( form ) {
132
- form . addEventListener ( "submit" , onSubmitEvent ) ;
133
- }
134
-
135
- // Unbind the event listener when the component dismounts
136
- return ( ) => {
137
- if ( form ) {
138
- form . removeEventListener ( "submit" , onSubmitEvent ) ;
139
- }
140
- } ;
141
- } , [ ] ) ;
142
-
143
- return null ;
144
- }
0 commit comments