1
1
import { set as setJsonPointer } from "json-pointer" ;
2
- import React , {
3
- ChangeEvent ,
4
- createContext ,
5
- createElement ,
6
- Fragment ,
7
- MutableRefObject ,
8
- useContext ,
9
- useEffect ,
10
- useRef ,
11
- useState ,
12
- } from "preact/compat" ;
13
- import {
2
+ import type { ChangeEvent , MutableRefObject } from "preact/compat" ;
3
+ import { createContext , createElement , Fragment } from "preact" ;
4
+ import { useContext , useEffect , useRef , useState } from "preact/hooks" ;
5
+ import type {
14
6
ImportSourceBinding ,
15
7
ReactPyComponent ,
16
8
ReactPyVdom ,
@@ -67,7 +59,7 @@ export function Element({ model }: { model: ReactPyVdom }): JSX.Element | null {
67
59
}
68
60
69
61
function StandardElement ( { model } : { model : ReactPyVdom } ) {
70
- const client = React . useContext ( ClientContext ) ;
62
+ const client = useContext ( ClientContext ) ;
71
63
// Use createElement here to avoid warning about variable numbers of children not
72
64
// having keys. Warning about this must now be the responsibility of the client
73
65
// providing the models instead of the client rendering them.
@@ -83,10 +75,10 @@ function StandardElement({ model }: { model: ReactPyVdom }) {
83
75
function UserInputElement ( { model } : { model : ReactPyVdom } ) : JSX . Element {
84
76
const client = useContext ( ClientContext ) ;
85
77
const props = createAttributes ( model , client ) ;
86
- const [ value , setValue ] = React . useState ( props . value ) ;
78
+ const [ value , setValue ] = useState ( props . value ) ;
87
79
88
80
// honor changes to value from the client via props
89
- React . useEffect ( ( ) => setValue ( props . value ) , [ props . value ] ) ;
81
+ useEffect ( ( ) => setValue ( props . value ) , [ props . value ] ) ;
90
82
91
83
const givenOnChange = props . onChange ;
92
84
if ( typeof givenOnChange === "function" ) {
@@ -116,7 +108,7 @@ function UserInputElement({ model }: { model: ReactPyVdom }): JSX.Element {
116
108
function ScriptElement ( { model } : { model : ReactPyVdom } ) {
117
109
const ref = useRef < HTMLDivElement | null > ( null ) ;
118
110
119
- React . useEffect ( ( ) => {
111
+ useEffect ( ( ) => {
120
112
// Don't run if the parent element is missing
121
113
if ( ! ref . current ) {
122
114
return ;
@@ -181,10 +173,10 @@ function useImportSource(model: ReactPyVdom): MutableRefObject<any> {
181
173
const vdomImportSource = model . importSource ;
182
174
const vdomImportSourceJsonString = JSON . stringify ( vdomImportSource ) ;
183
175
const mountPoint = useRef < HTMLElement > ( null ) ;
184
- const client = React . useContext ( ClientContext ) ;
176
+ const client = useContext ( ClientContext ) ;
185
177
const [ binding , setBinding ] = useState < ImportSourceBinding | null > ( null ) ;
186
178
187
- React . useEffect ( ( ) => {
179
+ useEffect ( ( ) => {
188
180
let unmounted = false ;
189
181
190
182
if ( vdomImportSource ) {
0 commit comments