Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import React, { useEffect, useState } from 'react';
import { View, TouchableOpacity } from 'react-native';
import FontAwesome5 from 'react-native-vector-icons/FontAwesome5';
import { styles } from './styles';
import { userConfig } from '../../hooks/configUser';
const CheckBox = ({name, value, setValue, values}) => {
const [isCheck, setIsCheck] = useState(false);
const { getUserUpdateConfig, loading } = userConfig();
useEffect(() => {
if (value) {
setIsCheck(true)
}
}, [value]);
const onSubmit = () => {
getUserUpdateConfig({
notification_new_category: isCheck,
notification_new_collection: isCheck,
notification_new_image: isCheck,
notification_promotion: isCheck,
});
};
const onChange = ()=>{
setIsCheck(m=> !m);
values[name].value = 1;
setValue(values);
}
return (
<View>
<TouchableOpacity
style={isCheck ? styles.checkBoxActive : styles.checkBox}
onPress={onChange}>
{!!isCheck && (
<FontAwesome5
name={'check'}
size={15}
color={'#6033CC'}
/>)}
</TouchableOpacity>
</View>
);
};
export default CheckBox;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment