11import { pair , type PairedComponentProperties } from "@coven/pair/preact" ;
22import { assertStrictEquals } from "@std/assert" ;
33import { renderToString } from "preact-render-to-string" ;
4- import { useState } from "preact/hooks" ;
4+ import { useCallback , useState } from "preact/hooks" ;
5+ import { jsx } from "preact/jsx-runtime" ;
56
67const Render = ( usePairedState : typeof useState ) => {
78 const [ count , setCount ] = usePairedState ( 0 ) ;
8-
9- return (
10- < button onClick = { ( ) => setCount ( count + 1 ) } type = "button" >
11- { count }
12- </ button >
9+ const onClick = useCallback (
10+ ( ) => setCount ( ( currentCount ) => currentCount + 1 ) ,
11+ [ ] ,
1312 ) ;
13+
14+ return jsx ( "button" , { children : count , onClick, type : "button" } ) ;
1415} ;
1516
1617const Wanted = ( { children } : PairedComponentProperties < typeof useState > ) =>
@@ -24,17 +25,17 @@ Deno.test(
2425 "Generated HTML with a prop should be the same from using `pair` or doing everything manually" ,
2526 ( ) =>
2627 assertStrictEquals (
27- renderToString ( < PairedState key = { key } > { Render } </ PairedState > ) ,
28- renderToString ( < Wanted key = { key } > { Render } </ Wanted > ) ,
28+ renderToString ( jsx ( PairedState , { key, children : Render } ) ) ,
29+ renderToString ( jsx ( Wanted , { key, children : Render } ) ) ,
2930 ) ,
3031) ;
3132
3233Deno . test (
3334 "Generated HTML should be the same from using `pair` or doing everything manually" ,
3435 ( ) =>
3536 assertStrictEquals (
36- renderToString ( < PairedState > { Render } </ PairedState > ) ,
37- renderToString ( < Wanted > { Render } </ Wanted > ) ,
37+ renderToString ( jsx ( PairedState , { children : Render } ) ) ,
38+ renderToString ( jsx ( Wanted , { children : Render } ) ) ,
3839 ) ,
3940) ;
4041
0 commit comments