The issue I am facing is I am not able to load my swiper with dynamic data. If I am recieving lets say 10 data then I have to make 10 empty objects in an array to get the data displayed and for my dynamic data my cards are blank .
Dropping my code below, let me know how can i improve
import React, {useState, useEffect} from 'react';
import {StyleSheet, Text, View} from 'react-native';
import Swiper from 'react-native-deck-swiper';
import styled from 'styled-components';
function* range(start, end) {
for (let i = start; i <= end; i++) {
yield i;
}
}
@sathucandy at least wrap your code in a code block, it is easier to read, and put only the necessary (no need for styles for your question to be answered), also, check #153
The issue I am facing is I am not able to load my swiper with dynamic data. If I am recieving lets say 10 data then I have to make 10 empty objects in an array to get the data displayed and for my dynamic data my cards are blank . Dropping my code below, let me know how can i improve
import React, {useState, useEffect} from 'react'; import {StyleSheet, Text, View} from 'react-native';
import Swiper from 'react-native-deck-swiper'; import styled from 'styled-components';
function* range(start, end) { for (let i = start; i <= end; i++) { yield i; } }
const Recommendations = () => { const [cardsState, updateCardsState] = useState({ // cards: fetch('https://reactnative.dev/movies.json') // .then((response) => response.json()) // .then((json) => { // json.movies; // }), cards: [{}, {}, {}], swipedAllCards: false, swipeDirection: '', cardIndex: 0, });
useEffect(() => { fetch('https://reactnative.dev/movies.json') .then((response) => response.json()) .then((json) => { updateCardsState({ ...cardsState, cards: json.movies, //cardsState.cards.push(...json.movies), //[...json.movies], }); // console.log(json.movies); console.log(cardsState.cardIndex); console.log(cardsState.cards); }) .catch((error) => console.error(error));
}, [cardsState.cardIndex]);
const renderCard = (card, index) => { // console.log({cardsState.cards[index].id}); if ( typeof cardsState.cards !== 'undefined' && cardsState.cards.length > 0 ) { return (