반응형
SMALL
react-native-community/checkbox 컴포넌트로 개별클릭 될 수 있게 코드 구현하기.
import React, {useState, useEffect, useCallback} from 'react';
import CheckBox from '@react-native-community/checkbox';
export const Test = () = > {
const initialState = {
terms: false,
personal: false,
simple: false,
}
const [isSelected, setIsSelected] = useState(initialState);
return (
<View>
<View style={styles.checkView}>
<CheckBox
disabled={false}
value={isSelected.terms}
onValueChange={value => {
setIsSelected({
...isSelected,
terms: value,
});
}
style={styles.checkbox}
/>
<Text>이용약관</Text>
</View>
<View style={styles.checkView}>
<CheckBox
disabled={false}
value={isSelected.personal}
onValueChange={value => {
setIsSelected({
...isSelected,
personal: value,
});
}
style={styles.checkbox}
/>
<Text>개인정보처리방침</Text>
</View>
<View style={styles.checkView}>
<CheckBox
disabled={false}
value={isSelected.simple}
onValueChange={value => {
setIsSelected({
...isSelected,
simple: value,
});
}
style={styles.checkbox}
/>
<Text>간편주소이용동의</Text>
</View>
</View>
);
};
const styles = StyleSheet.create({
checkView: {
flexDirection: 'row',
alignItems: 'center',
},
checkbox: {
alignSelf: 'center',
},
})
이런식으로 구현할 수 있다.
반응형
LIST
'개발 > React Native' 카테고리의 다른 글
[에러] Too many re-renders. React limits the number of renders to prevent an infinite loop. (0) | 2023.06.27 |
---|---|
옵셔널 체이닝 (0) | 2023.06.27 |
2.10 Icons (0) | 2023.06.03 |
2.8 Weather (0) | 2023.06.02 |
2.7 Location (0) | 2023.06.02 |