Transition issues with dynamic slide rendering (without breaking other apis) #467
-
Hi there, I'm having issues with rendering dynamically fetched content. The client knows the total number of questions but not the next question until an answer has been selected. The following works with no transition issues: const scrollNext = useCallback(async () => {
if (emblaApi && !isFetching) {
const nextIndex = selectedIndex + 1
if (nextIndex === totalQuestions) return
emblaApi.scrollNext()
setIsFetching(true)
const nextQuestion = await fetchQuestions(surveyType, journeyId, authString)
if (nextQuestion?.questionDetails) {
setQuestions([...questions, nextQuestion.questionDetails])
}
setSelectedIndex(selectedIndex + 1)
setNextBtnEnabled(selectedIndex < totalQuestions)
setPrevBtnEnabled(selectedIndex > 0)
setIsFetching(false)
}
}, [...]) However it breaks I've looked at your suggestion towards infinite scrolling but it seems like there's a hefty overhead, considering the above works. Do you have any suggestions other than using the infinite scroll as a template in this use case? My main additional requirement to the arrows and dots example is: const nextQuestion = await fetchQuestions(surveyType, journeyId, authString)
if (nextQuestion?.questionDetails) {
setQuestions([...questions, nextQuestion.questionDetails]) // where setQuestions is useState<QuestionDetails[]>([questionSets])
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 16 replies
-
Hi, If I understand you correctly, you want to dynamically add slides after fetching them. The latest release introduces the Have you checked that out? Best, |
Beta Was this translation helpful? Give feedback.
Hi @remy90,
Assuming this is the requirement:
I would do it like this:
useState()
for theslides
: