Hide/Show components in react native

后端 未结 24 2028
囚心锁ツ
囚心锁ツ 2020-12-07 08:43

I\'m really new to React Native and I\'m wondering how can I hide/show a component.
Here\'s my test case:



        
24条回答
  •  旧巷少年郎
    2020-12-07 09:24

    I would do something like this:

    var myComponent = React.createComponent({
    
        getInitialState: function () {
            return {
                showCancel: false,
            };
        },
    
        toggleCancel: function () {
            this.setState({
                showCancel: !this.state.showCancel
            });
        }
    
        _renderCancel: function () {
            if (this.state.showCancel) {
                return (
                    
                        
                            Cancel
                        
                    
                );
            } else {
                return null;
            }
        },
    
        render: function () {
            return (
                 this.doSearch({input: text})} />
                {this._renderCancel()}          
            );
        }
    
    });
    

提交回复
热议问题