lazy-react 3.1.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # lazy-react
2
2
 
3
- [![npm version](https://badge.fury.io/js/lazy-react.svg)](https://badge.fury.io/js/lazy-react) [![Issue Count](https://codeclimate.com/github/jonathanobino/react-lazy/badges/issue_count.svg)](https://codeclimate.com/github/jonathanobino/react-lazy) [![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier) [![dependecies](https://david-dm.org/jonathanobino/react-lazy.svg)](https://david-dm.org)
4
-
3
+ [![npm version](https://badge.fury.io/js/lazy-react.svg)](https://badge.fury.io/js/lazy-react) [![Issue Count](https://codeclimate.com/github/jonathanobino/react-lazy/badges/issue_count.svg)](https://codeclimate.com/github/jonathanobino/react-lazy) [![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
5
4
 
6
5
  Utility components to lazy load images, images-as-background and iframes using only requestAnimationFrame to handle scroll (both vertical and orizzontal) and window resize.
7
6
 
@@ -124,6 +123,43 @@ class Example extends React.Component {
124
123
  }
125
124
  ```
126
125
 
126
+ ## Hook
127
+
128
+ Since version 3.x there is an hook available named 'useIsInViewport' that exposes 3 elements:
129
+
130
+ - setRef: used to set the ref of the dom that has to be in the viewport
131
+ - link: the passed link. It's equal to '' until the element is in the specified viewport
132
+ - isVisible: it's false until the element is in the specified viewport
133
+
134
+
135
+ Usage
136
+
137
+ ```javascript
138
+
139
+ import useIsInViewport from 'lazy-react'
140
+
141
+ function Example(props) {
142
+ const [setRef, link, isVisible] = useIsInViewport(props)
143
+
144
+ if(!isVisible){
145
+ return <Placeholder />
146
+ }
147
+
148
+ return <div ref={(node)=>{
149
+ setRef(node)
150
+ }}>
151
+ <Content/>
152
+ </div>
153
+
154
+ }
155
+
156
+ ```
157
+
158
+ The required props that have to be passed to the hooks are:
159
+
160
+ - link: string
161
+ - offset: number
162
+
127
163
  ## Contributing
128
164
 
129
165
  Pull requests for bug fixes, new features, and improvements are welcomed.
package/demo/index.html CHANGED
@@ -28,6 +28,7 @@
28
28
  .styledImage{
29
29
  height: 500px;
30
30
  border: 10px solid tomato;
31
+ box-sizing: border-box;
31
32
  }
32
33
  </style>
33
34
  </head>