question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`isReactComponent()` returns false for components without `render()`

See original GitHub issue

I have few components which render() method encapsulated into mixin. Like so:

var Mixin = {
  render() {
    return (
      <h1>{ this.prop.header }</h1><div>{ this._renderBody() }</div>
    );
  }
};

var Comp1 = React.createClass({
  mixins: [ Mixin ],
  _renderBody() {
    return 'comp 1';
  }
});

var Comp2 = React.createClass({
  mixins: [ Mixin ],
  _renderBody() {
    return 'comp 2';
  }
});

And because of that some rules are ignored (e.g. sort-comp rule).
So I propose to check when there is no render() method inside component if the mixins prop is declared or not.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lencionicommented, Jul 24, 2016

It might be useful to check out react-codemod’s ReactUtils to see the methods they use for this kind of thing.

0reactions
ljharbcommented, Jan 27, 2018

I’m going to close this; in general, component detection needs some work, but there’s been many updates since this was filed.

New issues with concrete and actionable improvements are welcome!

Read more comments on GitHub >

github_iconTop Results From Across the Web

isReactComponent() returns false for components without ...
I have few components which render() method encapsulated into mixin. Like so: var Mixin = { render() { return ( <h1>{ this.prop.header }</h1>< ......
Read more >
How to detect a React component vs. a React element?
Notice the other functions, to determine if a react-element, use the isClassComponent() , yet it returns false for a legitimate React class component....
Read more >
React.Component
The render() method is the only required method in a class component. ... render() will not be invoked if shouldComponentUpdate() returns false.
Read more >
How to write a React component without using classes or hooks
This new object component can have its own state and methods, some of which can be lifecycle methods (render, componentDidMount, etc.) which ...
Read more >
ReactJS | Lifecycle of Components - GeeksforGeeks
If returned false then the subsequent steps of rendering will not be carried out. This function can't be used in the case of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found