Created
June 3, 2019 15:13
-
-
Save luandevpro/036b4c3ae15d55af5a84081036119920 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { View, Text } from 'react-native'; | |
import { CheckBox } from 'react-native-elements'; | |
import { ErrorMessage } from 'formik'; | |
const _languages = ['vi', 'vn', 'en']; | |
export default function CustomCheckBox(props) { | |
const handleOnPress = (_language, checked) => { | |
if (!checked) { | |
props.arrayHelpers.push(_language); | |
} else { | |
const idx = props.arrayHelpers.form.values.languages.indexOf( | |
_language, | |
); | |
props.arrayHelpers.remove(idx); | |
} | |
}; | |
return ( | |
<View> | |
{ | |
_languages.map((_language) => { | |
const checked = props.arrayHelpers.form.values.languages.includes(_language); | |
return ( | |
<View key={_language}> | |
<CheckBox | |
title={_language} | |
name={props.arrayHelpers.name} | |
value={_language} | |
checked={checked} | |
onPress={() => handleOnPress(_language, checked)} | |
/> | |
</View> | |
); | |
}) | |
} | |
<ErrorMessage | |
name={props.arrayHelpers.name} | |
render={msg => <Text>{msg}</Text>} | |
/> | |
</View> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment