Using imported JSON file as source only works when spreading into new object
See original GitHub issueOverview
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: Buglabel to this issue.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@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:
start()function if theplayprop istrueand the animation is not currently playingstop()function if theplayprop isfalseand the animation is currently playingJust an idea based on very little experience using this or other lottie players.
Hi @kb-ig, thanks for creating this issue, I’ll look in to it.