question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using imported JSON file as source only works when spreading into new object

See original GitHub issue

Overview

When using an imported lottie JSON file as the src rather than specifying a URL, I have to spread the JSON object into a new object every time the component renders, otherwise the animation doesnt play. I’m not sure if there’s a valid reason for it or it’s a bug.

This doesnt work - the animation doesnt play:

import AnimationData from "./animation.json";
//...
<Player src={AnimationData} ... />

But this does work - the animation plays

import AnimationData from "./animation.json";
//...
<Player src={{...AnimationData}} ... />

Consuming repo

What repo were you working in when this issue occurred?

I’ve reproduced this in a couple of repos, including this codesandbox.

Labels

  • Add the Type: Bug label to this issue.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kb-igcommented, Mar 8, 2022

@samuelOsborne No, no difference really, other than taking away some of the visual noise of capturing the instance and calling a function on the instance. It would really just be a convenience prop, that would:

  • call the start() function if the play prop is true and the animation is not currently playing
  • call the stop() function if the play prop is false and the animation is currently playing

Just an idea based on very little experience using this or other lottie players.

1reaction
samuelOsbornecommented, Mar 8, 2022

Hi @kb-ig, thanks for creating this issue, I’ll look in to it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Load local JSON file into variable - Stack Overflow
My solution, as answered here, is to use: var json = require('./data.json'); //with path. The file is loaded only once, further requests use...
Read more >
How To Work with JSON in JavaScript - DigitalOcean
This tutorial provides an introduction to working with JSON in JavaScript. Some general use cases of JSON include: storing data, ...
Read more >
Reshaping JSON with jq - Programming Historian
JSON lines files, the only way to check what type you are getting is to open the file in a text editor (or...
Read more >
Working With JSON Data in Python
In this tutorial you'll learn how to read and write JSON-encoded data using Python. You'll see hands-on examples of working with Python's built-in...
Read more >
Load JSON - APOC Extended Documentation - Neo4j
This section describes procedures that can be used to import JSON data from web APIs ... Sources with multiple JSON objects (JSONL,JSON Lines)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found