Skip to content

Commit

Permalink
docs: fix context example
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermerodz committed Mar 16, 2024
1 parent d8ba00d commit 8a9b1aa
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,19 +425,26 @@ NOTE: this also affects the selected caret position after a touch/click.
+import { OTPInputContext } from 'input-otp'

function MyForm() {
+ const inputContext = React.useContext(OTPInputContext)
return (
<OTPInput
- // First remove the `render` prop
- render={...}
>
+ {/* Then consume context */}
<OTPInputWrapper />
</OTPInput>
)
}

+function OTPInputWrapper() {
+ const inputContext = React.useContext(OTPInputContext)
+ return (
+ <>
+ {inputContext.slots.map((slot, idx) => (
+ <Slot key={idx} {...slot} />
+ ))}
+ </OTPInput>
)
}
+ </>
+ )
+}
```

NOTE: this also affects the selected caret position after a touch/click.
Expand Down

0 comments on commit 8a9b1aa

Please sign in to comment.