Logo
Chakra-UIReactJsNext.JS
Head

@codecraftkit

Documentation

useNearScreen

Description#

The useNearScreen is used to render components in a lazy way, it uses the browser api IntersectionObserver.

Installation#

bashjsx live=false npm i @codecraftkit/use-near-screen

Code Example

## Import
it can be imported from hooks.
```jsx live=false
import { useNearScreen } from "@codecraftkit/hooks";
```
or alone.
```jsx live=false
import { useNearScreen } from "@codecraftkit/use-near-screen";
```
## Usage
This hook allows you to to hide a component that is not in the view
```jsx live=false
function MyApp() {
const [show, element] = useNearScreen()
return <Grid>
<Box h="500px">1</Box>
<Box h="500px">2</Box>
<Box h="500px">3</Box>
<Box h="500px">4</Box>
<Box h="500px">5</Box>
<Box h="500px" ref={element}>
{
show && <Box> // item to hide
6
</Box>
}
</Box>
</Grid>
}
```
## Arguments
It doesn't take any arguments
## Results
<PropsList propsData={useNearScreenResults} headProps={headResults} />