Open AndresTIY opened 4 years ago
same issue happening for me! Please help if anyone has the solution. using react-native: 0.61.4
React Native 0.61.2 here! Attempt 3: Updating card index using redux Expected Behavior: Docs mention using redux or any other state management to update the card index. Expected the redux change to force a re-render.
//action.js
export const setCardIndex = index => ({ type: SET_CARD_INDEX, cardIndex: index)}
//reducer.js
const reducer = ( state = initialState, action) => {
switch(action.type){
case SET_CARD_INDEX: {
return {
...state,
cardIndex: action.cardIndex,
}
}
}
// swipe component js
const Screen = () => {
const { cardIndex = 0 } = useSelector(state => state.reducer)
const onSwipedRight = () => {
dispatch(setCardIndex(cardIndex + 3))
}
return <Swiper cardIndex={cardIndex} {... rest of the stuff} />
}
Actual Behavior: Nothing changes
I'm using this deck swiper as a way to answer questions. So the swiping actions correspond with answers such as "yes, no, maybe".
Now if the user answers with a no or maybe, then I want the next card to show different content rather than the next question.
So if the question is "Do you like deck swiper?" and I answer "maybe", then I want the next card to show "Maybe? Deck swiper is awesome!"
I attempted several things.. Attempt 1: Changing questions array with State
Expected Behavior: Changing local state triggers a re-render. I expect the Swiper component to re-render with the new card items when the state is changed.
Actual Behavior: The next card item is empty. The swiper is not updating sadly.
Attempt 2: Updating the card index
Expected Behavior: The docs mention updating the
cardIndex
in order to force a re-render using redux or any other state management. Figured I could manipulate the data array to contain questions and responses.Actual Behavior: Nothing changes. If I initially set the
cardIndex
to any other number than 0, then that indexed item will display. Otherwise, changing thecardIndex
creates no changesAny recommendations on this situation?
Thanks!