File tree Expand file tree Collapse file tree 1 file changed +4
-8
lines changed
packages/template-retail-react-app/app/components/swatch-group Expand file tree Collapse file tree 1 file changed +4
-8
lines changed Original file line number Diff line number Diff line change @@ -75,20 +75,17 @@ const SwatchGroup = (props) => {
7575 return
7676 }
7777 const childrenArray = Children . toArray ( children )
78- const index = childrenArray . findIndex ( ( child ) => child ?. props ?. value === value )
78+ const index = childrenArray . findIndex ( ( { props } ) => props ?. value === value )
7979
80- setSelectedIndex ( index >= 0 ? index : 0 )
80+ setSelectedIndex ( index )
8181 } , [ ] )
8282
8383 // Whenever the selected index changes ensure that we call the change handler.
8484 useEffect ( ( ) => {
8585 const childrenArray = Children . toArray ( children )
86- const selectedChild = childrenArray [ selectedIndex ]
86+ const newValue = childrenArray [ selectedIndex ] . props . value
8787
88- if ( selectedChild ?. props ?. value ) {
89- const newValue = selectedChild . props . value
90- handleChange ( newValue )
91- }
88+ handleChange ( newValue )
9289 } , [ selectedIndex ] )
9390
9491 return (
@@ -108,7 +105,6 @@ const SwatchGroup = (props) => {
108105 ) }
109106 < Flex ref = { wrapperRef } { ...styles . swatchesWrapper } >
110107 { Children . toArray ( children ) . map ( ( child , index ) => {
111- if ( ! child ?. props ) return null
112108 const selected = child . props . value === value
113109 return React . cloneElement ( child , {
114110 handleSelect : handleChange ,
You can’t perform that action at this time.
0 commit comments