Skip to content

Commit

Permalink
fix: restrict type on the "as" prop
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mparisot-mm committed Feb 23, 2023
1 parent 2273255 commit 048bcb0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

[![Version Badge][npm-version-svg]][package-url]
[![GZipped size][npm-minzip-svg]][bundlephobia-url]
[![Test][test-image]][test-url]
[![License][license-image]][license-url]
[![Test][test-image]][test-url] [![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

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

| Name | Type | Default | Description |
| ------------ | ---------------------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **as** | `string` | `'div'` | Render the wrapping element as this element. Defaults to `div`. |
| **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. |
| **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. |

### Intersection Observer v2 🧪
Expand Down
5 changes: 4 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ export type PlainChildrenProps = IntersectionOptions & {

/**
* Render the wrapping element as this element.
* This need to be an intrinsic element.
* If you want to use a custom element, please use the useInView
* hook to manage the ref explicitly.
* @default `'div'`
*/
as?: React.ElementType;
as?: keyof JSX.IntrinsicElements;

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

0 comments on commit 048bcb0

Please sign in to comment.