-
-
Notifications
You must be signed in to change notification settings - Fork 31
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 #19 from gregberge/various-improvements
various improvements
- Loading branch information
Showing
8 changed files
with
100 additions
and
29 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
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
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,37 @@ | ||
# Refs | ||
|
||
One of the biggest feature of `twc` is the automatic forwarding of `ref` prop. You don't have to worry about it any more. | ||
|
||
## Usage | ||
|
||
Take this component with a forwarded ref. | ||
|
||
```tsx /React.forwardRef/ | ||
import * as React from "react"; | ||
|
||
const Card = React.forwardRef< | ||
HTMLDivElement, | ||
React.HTMLAttributes<HTMLDivElement> | ||
>(({ className, ...props }, ref) => ( | ||
<div | ||
ref={ref} | ||
className="rounded-lg border bg-slate-100 text-white shadow-sm" | ||
{...props} | ||
/> | ||
)); | ||
``` | ||
|
||
With `twc`, the `ref` prop is automatically forwarded: | ||
|
||
```tsx | ||
const Card = twc.div`rounded-lg border bg-slate-100 text-white shadow-sm`; | ||
``` | ||
|
||
So you can safely use `ref` on `Card` component: | ||
|
||
```tsx /ref/ | ||
function CardDemo() { | ||
const ref = useRef(); | ||
return <Card ref={ref}>TWC is magic!</Card>; | ||
} | ||
``` |
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