Skip to content

Commit 412da1e

Browse files
authored
Merge pull request #615 from mparisot/restrict-as
fix: restrict type on the "as" prop
2 parents 2273255 + 3557c99 commit 412da1e

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Version Badge][npm-version-svg]][package-url]
44
[![GZipped size][npm-minzip-svg]][bundlephobia-url]
5-
[![Test][test-image]][test-url]
5+
[![Test][test-image]][test-url]
66
[![License][license-image]][license-url]
77
[![Downloads][downloads-image]][downloads-url]
88

@@ -167,7 +167,7 @@ The **`<InView />`** component also accepts the following props:
167167

168168
| Name | Type | Default | Description |
169169
| ------------ | ---------------------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
170-
| **as** | `string` | `'div'` | Render the wrapping element as this element. Defaults to `div`. |
170+
| **as** | `IntrinsicElement` | `'div'` | Render the wrapping element as this element. Defaults to `div`. If you want to use a custom component, please use the `useInView` hook or a render prop instead to manage the reference explictly. |
171171
| **children** | `({ref, inView, entry}) => ReactNode` or `ReactNode` | `undefined` | Children expects a function that receives an object containing the `inView` boolean and a `ref` that should be assigned to the element root. Alternatively pass a plain child, to have the `<InView />` deal with the wrapping element. You will also get the `IntersectionObserverEntry` as `entry`, giving you more details. |
172172

173173
### Intersection Observer v2 🧪

src/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ export type PlainChildrenProps = IntersectionOptions & {
5656

5757
/**
5858
* Render the wrapping element as this element.
59+
* This needs to be an intrinsic element.
60+
* If you want to use a custom element, please use the useInView
61+
* hook to manage the ref explicitly.
5962
* @default `'div'`
6063
*/
61-
as?: React.ElementType;
64+
as?: keyof JSX.IntrinsicElements;
6265

6366
/** Call this function whenever the in view state changes */
6467
onChange?: (inView: boolean, entry: IntersectionObserverEntry) => void;

0 commit comments

Comments
 (0)