Comparing two components - is Component X an instance of Component A

后端 未结 2 898
野性不改
野性不改 2020-12-20 13:31

I have a generic component which maps its child components to filter only children of a certain type, as found below.

However, using the property type w

2条回答
  •  星月不相逢
    2020-12-20 14:38

    The kind of api you're making is frail and confusing. You shouldn't treat elements as data. If you need to filter, pass data to the component.

    }, {type: 'Bar', element: }, {type: 'Bar', element:
    I'm lying but it doesn't matter
    }, ]} />
    var Main = React.createClass({
        render: function(){
            var filteredChildren = this.props.things.map(function(thing){
                return thing.type === 'Foo' ? thing.element : false;
            });
    
            return 
    {filteredChildren}
    ; } });

提交回复
热议问题