Display `this._carousel.currentIndex`
See original GitHub issueI don’t understand currentIndex
.
If I put it inside an onPress
method, it works as it should, but I am not able to print it in a <Text>
.
It says that this._carousel
is undefined.
I am defining this._carousel
with
<Carousel
ref={carousel => { this._carousel = carousel; }}
...
See the code below.
elements.map((el, i) => {
return (
<TouchableOpacity onPress={() => alert(this._carousel.currentIndex)}>
<Text>{this._carousel.currentIndex}</Text>
</TouchableOpacity>
)
})
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Display `this._carousel.currentIndex` · Issue #116 - GitHub
I don't understand currentIndex. If I put it inside an onPress method, it works as it should, but I am not able to...
Read more >Display current index of iCarousel in a label which is not a ...
The index for a given item view in the carousel. Works for item views and placeholder views, however placeholder view indexes do not...
Read more >How to build a multi-image carousel in React and Tailwind
You can view the finished multi-item carousel here ... We check to see if the currentIndex value is greater than zero and if...
Read more >ngx-hm-carousel - npm
A light carousel for Angular, support mobile touch by hammerJs with SSR. ... export class DragOneComponent { currentIndex = 0; speed = 5000; ......
Read more >How to Show Multiple Item in Simple React Carousel
Tagged with react, carousel, javascript, css. ... show-${show}`} + style={{ transform: `translateX(-${currentIndex * (100 / show)}%)` ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Easiest solution is not to use the
ref
.The reason it doesn’t work, is the component itself doesn’t get re-rendered, which means that it will always display the value at render time.
A better solution would be to use
onSnapToItem
to set state inside the component that uses the carousel. Something like this, (not tested, just writing from memory)Think that should do it…
The last project does not execute this programmatically;