Reputation: 11
I want to return current state in function, which is returning object.
myFunction = () => {
return (
myObject = {
object: this.state.variable
}
)
}
render() {
return (
<TouchableOpacity
onPress={() => {this.setState({ variable: 2 }), () => console.log(myFunction())}>
</TouchableOpacity> )
}
Function is returning state, which was default. I want to return new state, which was setted.
Upvotes: 0
Views: 52
Reputation: 5
Try this one:
render() {
return (
<TouchableOpacity
onPress={() => {
const value = 2;
this.setState({ variable: value });
console.log(myFunction(value);
}
}></TouchableOpacity>
)
}
myFunction = (value) => {
return (
myObject = {
object: value,
},
),
}
Upvotes: 0
Reputation: 4023
Try this one:
render() {
return (
<TouchableOpacity onPress={() => {
this.setState({ variable: 2 },
()=>console.log(this.myFunction()));
}>
</TouchableOpacity> )
}
Upvotes: 1