Issue
i have made custom component from react native picker and want to update value in formik when i change it but it say undefined variable setFieldValue when i pass it in my custom component prop as callback function how can i set formik value from my custom component below is my custom compoment which i have imported in formik page
<Formik
initialValues={{
calltype: '',
callfrom: '',
callto: '',
calldate: '',
joinedby: [],
tripinfo: {},
additionalinfo: '',
autoaccept: null,
}}
// validationSchema={CallValidationSchema}
onSubmit={(values, {setSubmitting, resetForm}) => {
setSubmitting(false);
sendValues(values);
}}>
{({
submitForm,
handleBlur,
touched,
errors,
values,
handleChange,
}) => (
<View>
<ARow
row
justifyContent="space-between"
alignItems={'flex-end'}>
<ACol col={6}>
<Picker
callbeck={getdata}
fieldname="calltype"
data={pickerdata}
inputBgColor="#F5F5F5"
heading="Call Type"
placeholder={'Select Call Type'}
onerror={false}
color={'#A9A9A9'}
value={values.calltype}
/>
{errors.calltype && touched.calltype ? (
<AText color={'red'} pb={'5px'}>
{errors.calltype}
</AText>
) : null}
</ACol>
<ACol col={6}>
<AText xtrasmall right>
#1100669
</AText>
</ACol>
</ARow>
</View>
)}
</Formik>
const CustomPicker = ({
<Picker
style={{
color: color ?? '#0D4D8D',
margin: -16,
height: 68,
marginRight: -12,
marginLeft: -4,
}}
selectedValue={selected}
onValueChange={(itemValue, itemIndex) => {
callbeck(fieldname, itemValue);
setSelected(itemValue);
}}>
<Picker.Item style={{fontSize: 12}} value="" label={placeholder} />
{!isEmpty(data) &&
data.map(item => (
<Picker.Item
style={{fontSize: 12}}
label={item.name}
value={item.id}
/>
))}
</Picker>
);
};
Solution
Ok Issue is Solved i have not destructured formik properly thats why its saying undefined variable setFieldValue,now when i send setFieldValue function in prop it works..
Answered By - Mohammed Maheswer
Answer Checked By - - Dawn Plyler (ReactFix Volunteer)