Skip to content Skip to sidebar Skip to footer

Withstore: Cannot Read Property 'state' Of Undefined (pure-react-carousel)

I use pure-react-carousel library and try to navigate to specific slide by onClick method of my Button. Please explain me how to use setStoreState because I tried to do it by myse

Solution 1:

I am actually an author for Pure React Carousel.

WithStore() only works if it is a child of <CarouselProvider />

WithStore accesses React's context API. CarouselProvider creates the context. When you create a context, React only passes the context down to child components of the component that created the context.

So, the use of WithStore in this pseudo-code example will give you the error.

<YourComponentThatUsesTheWithStoreHOC /><CarouselProvider>
  // all your buttons, slides, dots, etc...
</CarouselProvider>

This will also give you that errod.

<CarouselProvider>
  // all your buttons, slides, dots, etc...
</CarouselProvider><YourComponentThatUsesTheWithStoreHOC />

This pseudo-code example will work

<CarouselProvider>
  // all your buttons, slides, dots, etc...
  <YourComponentThatUsesTheWithStoreHOC /></CarouselProvider>

Solution 2:

The Parenthese are unnecessary. Try this:

exportdefaultWithStore(MyComponent, state => {
    currentSlide: state.currentSlide,
  });

Post a Comment for "Withstore: Cannot Read Property 'state' Of Undefined (pure-react-carousel)"