Skip to content

How can I be notified when a rendered item is displayed #791

Answered by vricosti
vricosti asked this question in Q&A
Discussion options

You must be logged in to vote

Finally I used handleSnapToItem with a isVisible prop:

 const [viewedItems, setViewedItems] = useState<Set<number>>(new Set());
 
const handleSnapToItem = (index: number) => {
    console.log("current index:", index);
    if (!viewedItems.has(index)) {
      console.log(`First time viewing item at index: ${index}`);
      setViewedItems(prev => new Set(prev).add(index)); // Mark as viewed
    }
  }; 
  
  ...
  <RemoteCtlCarouselItem 
            key={index} 
            index={index} 
            fullWidth={fullWidth}
            showButtons={showButtons}
            visualDebug={visualDebug}
            isVisible={viewedItems.has(index)} // Pass visibility prop
          />
 ...

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by vricosti
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant