Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination 'carouselRef' warning when carouselRef is set #198

Closed
wkwyatt opened this issue Oct 26, 2017 · 4 comments
Closed

Pagination 'carouselRef' warning when carouselRef is set #198

wkwyatt opened this issue Oct 26, 2017 · 4 comments

Comments

@wkwyatt
Copy link

wkwyatt commented Oct 26, 2017

Hi @archriss,

I have a snap-carousel component with pagination (GREAT repo by the way!馃憤馃徑 ). And everything works except I get this annoying error that the Pagination carouselRef isn't set when tappableDots is true, when it actually is set..... and it works. So the warning error is the only issue.

@bd-arc
Copy link
Contributor

bd-arc commented Oct 27, 2017

Hi @wkwyatt,

That's because the carousel reference isn't available before the component has been fully initialized, and Pagination's init is usually much quicker than Carousel's one.

If you take a look at the example's source code, you'll see that I've used a simple trick to prevent this error:

    get example1 () {
        const { slider1Ref } = this.state;

        return (
            <View>
                <Carousel
                  ref={(c) => { if (!this.state.slider1Ref) { this.setState({ slider1Ref: c }); } }}
                />
                <Pagination
                  carouselRef={slider1Ref}
                  tappableDots={!!slider1Ref}
                />
            </View>
        );

Does this solves the issue for you?

@wkwyatt
Copy link
Author

wkwyatt commented Oct 27, 2017

Thanks it does, as I wrote the post I came up with this solution but was unsure if there was a better way.

             <Pagination
                  carouselRef={slider1Ref || {} }
                  tappableDots
                />

But thank you for responding so quickly :)

@bd-arc
Copy link
Contributor

bd-arc commented Oct 27, 2017

You're welcome ;-) I would also like to find a better solution, but that's the best I was able to come up with for now...

By the way, tappableDots expects a boolean, which means you should write tappableDots={sliderRef || false}.

@bd-arc bd-arc closed this as completed Oct 27, 2017
@wkwyatt
Copy link
Author

wkwyatt commented Oct 27, 2017

Yea you are right! Just fixed it lol...thats what I get for responding as soon as I woke up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants