react-native-banner-carousel
react-native-banner-carousel copied to clipboard
How to pass JSON of Images as Data Source?
I have to pass JSON of Image Urls and Image Description. It is only taking Array of Image Urls currently. How to pass a Array of JSON Objects which consist of Image Url, Image Name and Image Description? Thanks
you can use a state, in the useeffect load the api const [images, setImages] = useState([]); useEffect(() => { analytics().logEvent(Page_${props.navigation.state.routeName}, {}); api.get(apiEndpoints.news + '0' + '&limit=' + 12).then(response => { //console.log(JSON.stringify(response.data.data.contents)) setImages(response.data.data.contents); }).catch(error => { console.error(error); }); }, []);, set the state with the value, and in the Carousel apply map to the object <Carousel index={5} pageSize={BannerWidth} showsPageIndicator={true}> {images.map((image, index) => renderPage(image, index))} </Carousel>