Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react/require-render-return shouldn't warn if render method is imported #563

Closed
yamalight opened this issue Apr 22, 2016 · 6 comments
Closed
Labels

Comments

@yamalight
Copy link

I generally write components like this - one file for component, one for render method, e.g.:

Component.js

import render from './render';

const MyComponent = React.createClass({
    // some other logic here
    // ...
    render,
});
export default MyComponent;

render.js

export default () => <div>hello world!</div>;

Currently this produces a warning, while it actually shouldn't.

@ljharb
Copy link
Member

ljharb commented Apr 22, 2016

Linters generally don't look at the contents of other files. Since render is just a stateless function, why not render() { return <Render />; }?

@yamalight
Copy link
Author

@ljharb I guess render example wasn't really good here.
I typically have something like this as render function (mostly to just separate logic and layout):

export default function render() {
    const {something} = this.state;
    return (
        <div>
            <button onClick={this.functionInComponent}>{something}</button>
        </div>
    );
};

I am not saying linter should read other files, but it shouldn't produce the error here. My guess is ignoring such cases would be more than enough.

@ljharb
Copy link
Member

ljharb commented Apr 22, 2016

@yamalight right but still, that function is an SFC. why not just use it inline in jsx as a component?

@ljharb
Copy link
Member

ljharb commented Apr 22, 2016

(Also, the whole point of a react component is that logic and layout for the same component aren't separated)

@yamalight
Copy link
Author

I have this obsession of splitting code into really small files :)
Just let me know if you think this is not a valid issue - close it, and I'll just tweak linter per-line where needed.

@yannickcr
Copy link
Member

The pattern debate aside, I think it should be ignored by the rule since we cannot check if a return statement is present in the render method in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants