responsive-system 1.4.5 → 1.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import React, { useState } from 'react'
1
+ import React, { useState, useEffect } from 'react'
2
2
  import { ResponsiveProvider } from './index'
3
3
  import { useResponsive } from '../hooks'
4
4
  import { ResponsiveLayoutContext } from '../context'
@@ -32,7 +32,17 @@ const ResponsiveLayoutProviderInner: React.FC<ResponsiveLayoutProviderInnerProps
32
32
  const customResponsive = useResponsiveHook?.()
33
33
  const responsive = customResponsive || internalResponsive
34
34
 
35
- const [currentLayout, setCurrentLayout] = useState(defaultLayout)
35
+ // Inicializar el estado con el defaultLayout, asegurando que sea válido
36
+ const validLayout = (defaultLayout && LAYOUT_CONFIG[defaultLayout]) ? defaultLayout : DEFAULT_LAYOUT
37
+ const [currentLayout, setCurrentLayout] = useState(validLayout)
38
+
39
+ // Sincronizar si el defaultLayout cambia (aunque no debería en la mayoría de casos)
40
+ useEffect(() => {
41
+ const newValidLayout = (defaultLayout && LAYOUT_CONFIG[defaultLayout]) ? defaultLayout : DEFAULT_LAYOUT
42
+ if (newValidLayout !== currentLayout) {
43
+ setCurrentLayout(newValidLayout)
44
+ }
45
+ }, [defaultLayout, currentLayout])
36
46
 
37
47
  const layoutConfig = LAYOUT_CONFIG[currentLayout] || LAYOUT_CONFIG[DEFAULT_LAYOUT]
38
48