0

My question is : I want to render a view component on every key press. But its just calling 2 times only by default. Button is not working. I don't know where I'm doing wrong. Please help. Thanks.

function renderBottomComponent() {
        console.log("here");
            return (
                <View>
                    <Content />
                </View>
            )

    }


  <View style={styles.List}>
                       <View> 
                           <Content abc={this.mhandler} hel={'hahah'}/>

                       </View>

                       {this.renderBottomComponent()}

                </View>



<Button title="Add more" color='green' onPress={this.renderBottomComponent} />
3
  • What do you mean by render component on keyPress? Commented Jan 8, 2019 at 6:55
  • means i want to add components in the list upon key press ! Kindly tell me Commented Jan 8, 2019 at 6:57
  • 1
    refer this Commented Jan 8, 2019 at 6:59

1 Answer 1

0
export default class YourClass extends React.Component() {
  constructor(props) {
    super(props);
    this.state = {
        renderComponent: false
    };
    this.onClickHandler = this.onClickHandler.bind(this);
  }

  onClickHandler() {
    this.setState({renderComponent: !this.state.renderComponent})
  }

  render() {
    return (
        <View>
            {this.state.renderComponent && <YourComponent/>}
            <Button title="Add more" color='green' onPress={this.onClickHandler} />
        </View>
    );
}

I hope that will help you

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.