How to render JSX component from function to show it in the Screen.
This below is the code which is not rendering the function JSX component...
export default class HomeScreen extends Component{
state = {
isVisible:false
}
modal = ()=>{
return(<Text>Hello world</Text>);
}
render(){
return(
<View>
<Button onPress={this.setState({isVisible:true})}>Click me</Button>
{this.state.isVisible?this.modal:null}
</View>
);
}
}
And this Below code is working properly so i want to know what is error in first one.
export default class HomeScreen extends Component{
state = {
isVisible:false
}
modal = ()=>{
return(<Text>Hello world</Text>);
}
render(){
return(
<View>
<Button onPress={this.setState({isVisible:true})}>Click me</Button>
{this.state.isVisible?<Text>Hello world</Text>:null}
</View>
);
}
}
So Please tell me the error in first one what is problem due to which hello world text is not rendering through the JSX component return from the function modal.