How to return a boolean value from react native function?
2 Answers
If your function is in a class, you can do this (check toggleBool):
class IsTrue extends Component
{
state = {isTrue: false}
componentWillMount = () =>
{
const newVal = this.toggleBool();
this.setState({isTrue: newVal});
}
toggleBool = () =>
{
if (this.state.isTrue === false)
return (true);
return (false);
}
render = () => <Text>{this.state.isTrue}</Text>
}