File tree Expand file tree Collapse file tree 1 file changed +10
-17
lines changed
packages/core/src/CheckBox Expand file tree Collapse file tree 1 file changed +10
-17
lines changed Original file line number Diff line number Diff line change @@ -26,30 +26,23 @@ export interface CheckBoxProps extends TouchableOpacityProps {
2626 onChange ?: ( checked : boolean ) => void ;
2727}
2828
29- export interface CheckBoxState {
30- checked : boolean ;
31- controlChecked : 'props' | 'state' ;
32- }
33-
3429function CheckBox ( props : CheckBoxProps ) {
3530 const theme = useTheme < Theme > ( ) ;
36- const [ state , setState ] = useState ( {
37- checked : ! ! props . checked ,
38- controlChecked : 'props' ,
39- } ) ;
31+
32+ const [ state , setState ] = useState ( { checked : ! ! props . checked } ) ;
4033
4134 useEffect ( ( ) => {
42- if ( state . controlChecked === 'props' ) {
43- setState ( { ...state , checked : ! ! props . checked } ) ;
44- }
45- setState ( { ...state , controlChecked : 'props' } ) ;
46- } , [ ] ) ;
35+ setState ( { checked : ! ! props . checked } ) ;
36+ } , [ props . checked ] ) ;
4737
4838 const onPress = ( ) => {
4939 const { onChange } = props ;
50- setState ( { checked : ! state . checked , controlChecked : 'state' } ) ;
51-
52- onChange && onChange ( state . checked ) ;
40+ if ( Reflect . has ( props , 'checked' ) ) {
41+ onChange && onChange ( state . checked ) ;
42+ } else {
43+ setState ( { checked : ! state . checked } ) ;
44+ onChange && onChange ( state . checked ) ;
45+ }
5346 } ;
5447
5548 const {
You can’t perform that action at this time.
0 commit comments