Skip to content

Commit 048bcb0

Browse files
committed
fix: restrict type on the "as" prop
Restrict the usage of "as" to intrinsic components to avoid any issues with the ref. Add documentation to tell developers to use the hook otherwise.
1 parent 2273255 commit 048bcb0

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +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]
6-
[![License][license-image]][license-url]
5+
[![Test][test-image]][test-url] [![License][license-image]][license-url]
76
[![Downloads][downloads-image]][downloads-url]
87

98
React implementation of the
@@ -167,7 +166,7 @@ The **`<InView />`** component also accepts the following props:
167166

168167
| Name | Type | Default | Description |
169168
| ------------ | ---------------------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
170-
| **as** | `string` | `'div'` | Render the wrapping element as this element. Defaults to `div`. |
169+
| **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 instead to manage the reference explictly. |
171170
| **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. |
172171

173172
### 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 need 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)