File tree Expand file tree Collapse file tree 1 file changed +29
-25
lines changed
usehooks.com/src/content/hooks Expand file tree Collapse file tree 1 file changed +29
-25
lines changed Original file line number Diff line number Diff line change @@ -50,39 +50,43 @@ import StaticCodeContainer from "../../components/StaticCodeContainer.astro";
5050
5151``` jsx
5252import * as React from " react" ;
53- import { useLongPress } from " @uidotdev/usehooks" ;
54- import { closeIcon } from " ./icons" ;
53+ import { useMeasure } from " @uidotdev/usehooks" ;
5554
56- export default function App () {
57- const [isOpen , setIsOpen ] = React .useState (false );
58- const attrs = useLongPress (
59- () => {
60- setIsOpen (true );
61- },
62- {
63- onStart : (event ) => console .log (" Press started" ),
64- onFinish : (event ) => console .log (" Press Finished" ),
65- onCancel : (event ) => console .log (" Press cancelled" ),
66- threshold: 500 ,
67- }
55+ function Measure ({ type = " horizontal" }) {
56+ const [ref , { width , height }] = useMeasure ();
57+
58+ return (
59+ < figure>
60+ < figcaption>
61+ < span> {type}< / span>
62+ < / figcaption>
63+ < article
64+ ref= {ref}
65+ className= {type}
66+ style= {{
67+ resize: type
68+ }}
69+ >
70+ {type === " horizontal" ? (
71+ < label> width: {Math .floor (width)}< / label>
72+ ) : (
73+ < label> height: {Math .floor (height)}< / label>
74+ )}
75+ < / article>
76+ < / figure>
6877 );
78+ }
6979
80+ export default function App () {
7081 return (
7182 < section>
72- < h1> useLongPress< / h1>
73- < button {... attrs} className= " primary" >
74- Press Me
75- < / button>
76- {isOpen && (
77- < dialog>
78- < button onClick= {() => setIsOpen (false )}> {closeIcon}< / button>
79- < h2> Modal< / h2>
80- < p> This is a modal triggered by a long press.< / p>
81- < / dialog>
82- )}
83+ < h1> useMeasure< / h1>
84+ < p> (Resize the rulers)< / p>
85+ < Measure / >
8386 < / section>
8487 );
8588}
89+
8690```
8791
8892</StaticCodeContainer >
You can’t perform that action at this time.
0 commit comments