1

i am using react-native-snap-carousel for my first react-native app.

I have read docs but i see it use static data. But i want to get data form server with API, how can i do it?

Thank you for helping.

hoang viet
  • 23
  • 3

1 Answers1

0

You can fetch data from the server and pass it like so:

class MyCoponent extends React.Component{

   state = { data: null }

   fetchData = () => {
      // const result = fetch from api ... 
      this.setState(() => ({ data: result }))
   }

   render(){
      const { data } = this.state
      if(!data){
         return <Text>No data</Text>
      }
      return(
         <Carousel data={data}/>
      )
   }

}
Alexander Vitanov
  • 4,074
  • 2
  • 19
  • 22
  • i have fetch data from server and pass it, app no error but it didn't show the image. what wrong? i follow this example https://github.com/archriss/react-native-snap-carousel/tree/master/example – hoang viet Oct 20 '17 at 02:42