Closed ayush-lal closed 4 months ago
Same here. Just installed the library and used sample code from the readme. Used it with expo
I think this is happening because of the onChange method, please check the example in the docs. I fixed it by setting the date as string inside onChange method. You can also provide the code if It didn't fix the issue.
Seems like others have experienced this issue in the past, im not too sure if there is a work around to this? I have the latest version installed - v2.0.0
Component (also tried same setup from the examples):
<DateTimePicker mode="single" date={new Date()} onChange={handleDate} />
Error:
[0] ERROR RangeError: invalid array length [0] [0] This error is located at: [0] in DaySelector (at Calendar.tsx:16) [0] in RCTView (at View.js:116) [0] in View (at Calendar.tsx:34) [0] in RCTView (at View.js:116) [0] in View (at Calendar.tsx:26) [0] in Calendar (at DateTimePicker.tsx:301) [0] in DateTimePicker (at app/index.tsx:43) [0] in RCTView (at View.js:116) [0] in View (at app/index.tsx:34) [0] in Page (at useScreens.js:112) [0] in Unknown (at useScreens.js:116) [0] in Suspense (at useScreens.js:115) [0] in Route (at useScreens.js:131) [0] in Route(index) (at SceneView.tsx:132) [0] in StaticContainer [0] in EnsureSingleNavigator (at SceneView.tsx:124) [0] in SceneView (at useDescriptors.tsx:218) [0] in RCTView (at View.js:116) [0] in View (at DebugContainer.native.tsx:34) [0] in DebugContainer (at NativeStackView.native.tsx:82) [0] in MaybeNestedStack (at NativeStackView.native.tsx:325) [0] in RCTView (at View.js:116) [0] in View (at NativeStackView.native.tsx:318) [0] in RNSScreen (at createAnimatedComponent.js:54) [0] in Unknown (at src/index.native.tsx:314) [0] in Suspender (at src/index.tsx:40) [0] in Suspense (at src/index.tsx:39) [0] in Freeze (at src/index.native.tsx:206) [0] in DelayedFreeze (at src/index.native.tsx:313) [0] in InnerScreen (at src/index.native.tsx:566) [0] in Screen (at NativeStackView.native.tsx:253) [0] in SceneView (at NativeStackView.native.tsx:413) [0] in Suspender (at src/index.tsx:40) [0] in Suspense (at src/index.tsx:39) [0] in Freeze (at src/index.native.tsx:206) [0] in DelayedFreeze (at src/index.native.tsx:220) [0] in RNSScreenStack (at src/index.native.tsx:227) [0] in ScreenStack (at NativeStackView.native.tsx:401) [0] in NativeStackViewInner (at NativeStackView.native.tsx:474) [0] in RCTView (at View.js:116) [0] in View (at SafeAreaProviderCompat.tsx:42) [0] in SafeAreaProviderCompat (at NativeStackView.native.tsx:473) [0] in NativeStackView (at createNativeStackNavigator.tsx:72) [0] in PreventRemoveProvider (at useNavigationBuilder.tsx:718) [0] in NavigationContent (at useComponent.tsx:35) [0] in Unknown (at createNativeStackNavigator.tsx:71) [0] in NativeStackNavigator (at withLayoutContext.js:65) [0] in Unknown (at _layout.tsx:62) [0] in PortalProviderComponent (created by TamaguiProvider) [0] in Theme (created by ThemeProvider) [0] in ThemeProvider (created by TamaguiProvider) [0] in Provider (created by TamaguiProvider) [0] in TamaguiProvider (created by TamaguiProvider) [0] in TamaguiProvider (at _layout.tsx:60) [0] in Provider (at _layout.tsx:58) [0] in RootLayoutNav (at _layout.tsx:53) [0] in RootLayout [0] in Try (at useScreens.js:73) [0] in Unknown (at useScreens.js:112) [0] in Unknown (at useScreens.js:116) [0] in Suspense (at useScreens.js:115) [0] in Route (at useScreens.js:131) [0] in Route() (at ExpoRoot.js:90) [0] in RNCSafeAreaProvider (at SafeAreaContext.tsx:92) [0] in SafeAreaProvider (at ExpoRoot.js:55) [0] in wrapper (at ExpoRoot.js:89) [0] in EnsureSingleNavigator (at BaseNavigationContainer.tsx:430) [0] in BaseNavigationContainer (at NavigationContainer.native.js:105) [0] in ThemeProvider (at NavigationContainer.native.js:104) [0] in NavigationContainerInner (at ExpoRoot.js:86) [0] in ContextNavigator (at ExpoRoot.js:64) [0] in ExpoRoot (at qualified-entry.js:20) [0] in App (created by ErrorOverlay) [0] in ErrorToastContainer (created by ErrorOverlay) [0] in ErrorOverlay (at withDevTools.ios.js:25) [0] in withDevTools(ErrorOverlay) (at renderApplication.js:57) [0] in RCTView (at View.js:116) [0] in View (at AppContainer.js:127) [0] in RCTView (at View.js:116) [0] in View (at AppContainer.js:155) [0] in AppContainer (at renderApplication.js:50) [0] in main(RootComponent) (at renderApplication.js:67), js engine: hermes
Can you provide the handleDate
you passed to the onChange
prop in your example?
@farhoudshapouran just a simple console.log at this stage:
function handleDate(params: any) {
console.log(params);
}
Same issue , I've patched the project with patch-package. @farhoudshapouran I'm not sure if I should create a pull request as I don't know well your project.
But this is my change to make it work :
@@ -64,7 +69,7 @@ export function isDateBetween(
export const getFormatedDate = (date: DateType, format: string) =>
dayjs(date).format(format);
-export const getDate = (date: DateType) => dayjs(date, CALENDAR_FORMAT);
+export const getDate = (date: DateType) => dayjs(date, DATE_FORMAT);
export const getYearRange = (year: number) => {
const endYear = YEAR_PAGE_SIZE * Math.ceil(year / YEAR_PAGE_SIZE);
EDIT: Just found out that it is already fixed, I will wait for the package update.
@farhoudshapouran Let me provide the code, I just use it for single mode. In other modes, the data returns in a different way as I remember.
onChange={({ date: selectedDate }: { date: any }) => onChange(selectedDate as string)}
I just released v2.0.1 to npm please update it and check again
Seems to be working for me now. Thank you for addressing this @farhoudshapouran
Thanks to @Code-Hive-GmbH to fixing this issue
Seems like others have experienced this issue in the past, im not too sure if there is a work around to this? I have the latest version installed - v2.0.0
Component (also tried same setup from the examples):
Error: