I'm trying to add a competition entry to my competitions database in firebase but I'm getting the error:
TypeError: undefined is not an object (evaluating 'route.params.id')
Here's my code:
const AddEntry = ({route, navigation}) => {
const id = route.params.id
const [title, onChangeTitle] = React.useState('')
const [image, setImage] = React.useState("/")
const pickImage = async () => {
// No permissions request is necessary for launching the image library
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
aspect: [4, 3],
quality: 1,
});
console.log(result);
if (!result.cancelled) {
setImage(result.uri);
}
};
const AddEntry = async() => {
let imageUrl = await handleImageUpload()
addEntryToComp({title, imageUrl}, id)
}
//Image code here
return(
<View>
<Text>Add Entry</Text>
<Text>{id}</Text>
<Button title='Upload Entry Image' color="red" onPress={pickImage}></Button>
<Button title='Save' color="purple" onPress={AddEntry}></Button>
</View>
)
}
export default AddEntry
Any ideas?
Params are used for passing data to route by putting them in an object as a second parameter to the navigation.navigate function.
For example:
navigation.navigate('AddEntry', { id })
...and then you can access those passed params from route.params.
More here: https://reactnavigation.org/docs/params/