javascript - Detecting if a child component has a specific mixin/method in React.js -


In the render method of my component, I have to filter in the search for props.children variable components That is a specific method or property, but I am unable to expose any of the methods or qualities of children. I want to get the inherited method from a mixin.

Example:

  Bar BarMaxin = {isBar: function () {true; }}; Var Foo = React.createClass ({rendere: function () {var filteredChildren = this.props.children.filter (function) {return child.isBar ();}); Return (
Filtered children}
);}}); Unfortunately, this example does not work because child.isBar is undefined even when the child gets a mix of components. Barmixine .

Do I have some misunderstanding? I have also tried to declare my mixing methods such as stabilization:

{bar} bar = {static: {isBar: function () {return true; }}};

Any help would be greatly appreciated.

Edit:

I have found a work solution:

  var barMixin = {getDefaultProps: function ( ) {Return {isBar: function () {true}; }}; }};  

Check the render function with: child.props.isBar () . However, this is not the right way to do this.

I have a library to deal with the structure of a small child who can be easy for your problem If you need you can also deal with deep children. You can get it here:.

  'feedback' by import response; Import children from 'feedback-kids-utilities'; The ceremony is plum (baby) {back true; } Fuz Foo (Props) {Return  };  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -