@lottiefiles/lottie-player 1.5.7 → 1.5.8

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -171,21 +171,52 @@ declare namespace JSX {
171
171
  }
172
172
  ```
173
173
 
174
- ### NuxtJS
174
+ ### Nuxt 2
175
175
 
176
- The process for NuxtJS is slightly different. Create a lottie-player.js file in project root inside a folder named 'plugins'. Add the code below to the file
176
+ Create a `lottie-player.js` file inside the `/plugins` folder and add the below code to the file:
177
177
 
178
178
  ```js
179
179
  import * as LottiePlayer from "@lottiefiles/lottie-player";
180
+ ```
181
+ \
182
+ Open `nuxt.config.js` file and add the following entry to register the newly created plugin:
183
+
184
+ ```js
185
+ export default {
186
+ plugins: [{ src: "~/plugins/lottie-player.js", mode: "client" }]
187
+ }
188
+ ```
189
+
190
+ This is because the player script needs to be rendered on the browser/client side and we must configure Nuxt to load the script on the client side only.
191
+ \
192
+ You would then be able to use the player as follows inside any component:
193
+
194
+ ```html
195
+ <lottie-player
196
+ autoplay
197
+ controls
198
+ loop
199
+ style="width:400px"
200
+ src="https://assets3.lottiefiles.com/packages/lf20_RItkEz.json"
201
+ speed="1"
202
+ debug
203
+ />
180
204
  ```
181
205
 
182
- Open nuxt.config.js file and adjust the plugins array as shown below
206
+ ### Nuxt 3
207
+
208
+ The process for Nuxt 3 is slightly different.
209
+ Create a `lottie-player.client.ts` file inside the `/plugins` folder and add the below code to the file:
183
210
 
184
211
  ```js
185
- plugins: [{ src: "~/plugins/lottie-player.js", mode: "client" }],
212
+ import * as LottiePlayer from "@lottiefiles/lottie-player";
213
+
214
+ export default LottiePlayer;
186
215
  ```
216
+ \
217
+ Your plugin will be automatically available throughout your Nuxt application thanks to the [plugin auto-registration](https://v3.nuxtjs.org/guide/directory-structure/plugins). Note the `client` suffix in the name of the plugin - this tells Nuxt to load it only on the client side, as the Lottie Player script can only be rendered in the browser.
187
218
 
188
- You would then be able to use the player as follows inside any component
219
+ You would then be able to use the player as follows inside any component:
189
220
 
190
221
  ```html
191
222
  <lottie-player
@@ -196,14 +227,12 @@ You would then be able to use the player as follows inside any component
196
227
  src="https://assets3.lottiefiles.com/packages/lf20_RItkEz.json"
197
228
  speed="1"
198
229
  debug
199
- ></lottie-player>
230
+ />
200
231
  ```
201
232
 
202
- This is because the player script needs to be rendered on the browser/client side and we must configure nuxtjs to load the script on the client side only.
203
-
204
233
  ### NextJS
205
234
 
206
- The process to import in NextJS is similar to NuxtJS in the sense that on SSR mode, the library must be declared as a client side module. To do this, import the library within a react useEffect hook.
235
+ The process to import in NextJS is similar to Nuxt in the sense that on SSR mode, the library must be declared as a client side module. To do this, import the library within a react useEffect hook.
207
236
 
208
237
  ```javascript
209
238
  import React, { useRef } from "react";