hi, in one component I have a Formik form that when I submit it I get an object back, great!
So, how can I now submit that data in a function on another component with state?
this is my function on my HomeScreen class component that adds a report:
addReport = async report => {
try {
const [modalOpen, setModalOpen] = useState(false)
const snapshot = await firebase.database().ref('reports')
.child(this.state.currentUser.uid).orderByChild('name').equalTo(report).once('value')
if (snapshot.exists()) {
alert('Unable to add report as already exists')
} else {
const key = await firebase.database().ref('reports').child
(this.state.currentUser.uid).push().key
const response = await firebase.database().ref('reports').child(this.state.currentUser.uid).child(key)
.set({ name: report, saved: false })
this.setState((state, props) => ({
reports: [...state.reports, { name: report, saved: false }],
reportsNew: [...state.reportsNew, { name: report, saved: false }],
isAddNewReportVisible: false
}), () => { })
console.log(this.state.reports)
setModalOpen(false)
}
} catch (error) {
console.log(error)
}
}
and here is my Formik form on my other class component AddReportForm
<Formik
initialValues={{ name: '', latitude: this.props.latitude, longitude: this.props.longitude, read: false, saved: false }}
onSubmit={(values) => {
addReport(values)
}}
>
{(props) => (
<View>
<TextInput
multiline
style={styles.input}
placeholder='Name'
onChangeText={props.handleChange('name')}
value={props.values.name}
/>
<View style={globalStyles.button}>
<Button
color={colors.btnTextColor}
title='Submit' onPress={props.handleSubmit}
/>
</View>
</View>
)}
</Formik>