Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #622 from reach/rect-improvements
rect: Fix issues with the observer between renders
- Loading branch information
Showing
6 changed files
with
89 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from "react"; | ||
import { useRect } from "@reach/rect"; | ||
|
||
let name = "Change the observed ref"; | ||
|
||
function Example() { | ||
const refLeft = React.useRef<HTMLTextAreaElement>(null); | ||
const refRight = React.useRef<HTMLTextAreaElement>(null); | ||
const [whichRect, setWhichRect] = React.useState(true); | ||
const rect = useRect(whichRect ? refLeft : refRight); | ||
return ( | ||
<div> | ||
<pre> | ||
{whichRect ? "left" : "right"}: {JSON.stringify(rect, null, 2)} | ||
</pre> | ||
<button onClick={() => setWhichRect(!whichRect)}> | ||
Toggle Observed Ref | ||
</button> | ||
<div> | ||
<textarea ref={refLeft} defaultValue="resize this" /> | ||
<textarea ref={refRight} defaultValue="resize this" /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
Example.story = { name }; | ||
export const Comp = Example; | ||
export default { title: "Rect" }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters