React native: Use button to run a class

156 Views Asked by At

I am trying to run a class using a button but I can't make it work. I know that if I want to run a class I just need to use:

 <className /> 

So, I tried to do this:

    <Button
    title="Right button"
    onPress={() => <className />}
  />

However, I got an error so I'm probably doing something wrong. Can anyone help?

1

There are 1 best solutions below

0
On

"Running a class" doesn't really mean anything, so I'm going to have a stab at what you mean. Probably you want to render a class component when you click a button. In that case use something like:

  <Button
    title="Right button"
    onPress={() => this.setState({showMyComponent: true})}
  />
  { this.state.showMyComponent && <className /> }

Note this isn't complete - you probably want to also be able to hide it and so on, but it's a start.