MarceloPrado / flash-calendar

The fastest React Native calendar 📆⚡
https://marceloprado.github.io/flash-calendar/
MIT License
941 stars 26 forks source link

Can I create two instances of the <Calendar.List /> with useDateRange hooks ? #51

Open ioeldev opened 1 month ago

ioeldev commented 1 month ago

I have two screens with the Calendar.List but when one update the state of useDateRange it gets reflected on the second component, even though the Calendar.List have two different "key" props. Is it possible to instantiate the useDateRange twice ?

MarceloPrado commented 1 month ago

The useDateRange hook is a plain React hook that exposes a useState's value + some setters. Did you try something like this?

const YourApp = ({ currentScreen }) => {
  const dateRangePropsForFirstScreen = useDateRange()
  const dateRangePropsForSecondScreen = useDateRange()

  return currentScreen === 'one' ? 
    <ScreenOne {...dateRangePropsForFirstScreen} /> : 
    <ScreenTwo {...dateRangePropsForSecondScreen} />;
}
ioeldev commented 1 month ago

Will try, it's just that i am initializing the useDateRange inside of each components so i thought i wouldn't interfere

MarceloPrado commented 3 weeks ago

A repro example would be helpful to understand what's going on