17. How can I use a remote Lottie animation file in my app?
The simplest approach would be to use fetch()
to download the JSON file, parse it, and set it in a state variable so that it can be used as a source
prop in a LottieView
container:
import React, {useState, useEffect} from 'react';
import LottieView from 'lottie-react-native';
import {SafeAreaView, View} from 'react-native';
const App = ({}) => {
const [animation, setAnimation] = useState();
useEffect(() => {
fetch('https://myserver.com/animation.json', {
method: 'GET',
})
.then(response => response.json())
.then(responseJSON => {
setAnimation(responseJSON);
}...