const change = (e) => {
console.log(e)
//Firebase.database().ref(`userSubject/${subjectTaken.user}/${subjectTaken.id}/topics/${name}/`).update({"completed": !completed})
}
return (
<View style={styles.page} >
<Header type="dark-profile" title={subjectTaken.name} desc="Here is your progress. You can do this!" onPress={() => navigation.goBack()}/>
<View>
{topic.map(item => {
if(item.completed === true) {
return <TodoBox text={item.lesson} type={true} onPress={() => console.log("YEY")} />
} else {
const name = item.lesson
return (
<TodoBox text={item.lesson} type={false} onPress={(name) => {this.change(item.lesson)}} />
)
}
})}
</View>
</View>
)
}
I am wondering how i can pass the variable item.lesson to the function that i inserted on onpress... log gives me undefined why
CodePudding user response:
In this snippet, you are passing name
as a parameter, so the function does not know about item
.
Also, it looks like the onChange
function requires an event
as a parameter.
CodePudding user response:
okay i got it thank you.. what i did was to not pass in any parameter to the onpress