Search code examples
androidreact-nativelottie

How to use Lottie Json file with arrow function in React-Native


How to use lottie Jason File with arrow function In React-Native

This code working correctly

import React from 'react';
import LottieView from 'lottie-react-native';

export default class BasicExample extends React.Component {
  render() {
    
    return (
 
    <LottieView source={require('./lotties/rocket.json')} autoPlay loop />
 
    )
  }
}

But this code not working it giving error. How to use LottieView with arrow function

import React from 'react';
import LottieView from 'lottie-react-native';

const App = () => {
  render(); {
    return(
      <LottieView source={require('./lotties/rocket.json')} autoPlay loop />
    );
  }
}
export default App;

Solution

  • This is not how you write functional components

    const App = () => {
      render(); {
        return(
          <LottieView source={require('./lotties/rocket.json')} autoPlay loop />
        );
      }
    }
    

    you don't have to create a render function inside it, try the following

    const App = () => {
        return(
          <LottieView source={require('./lotties/rocket.json')} autoPlay loop />
        );
    }