0

eslinting with airbnb

import React from 'react';
import TopBar from './topBar';
import Content from './content';

class App extends React.Component {
  render() {
    return (
      <div className="app">
        <TopBar />
        <Content />
      </div>
    );
  }
}

export default App;

gives the error

5:1  error  Component should be written as a pure function  react/prefer-stateless-function

I have tried

function render(){}

and

render: function() {}

but didn't succeed

TylerH
  • 20,799
  • 66
  • 75
  • 101
Gaurav Gupta
  • 1,929
  • 4
  • 21
  • 40
  • 3
    read this: https://facebook.github.io/react/docs/reusable-components.html#stateless-functions – azium Jun 13 '16 at 15:53

1 Answers1

1

Using the docs from https://facebook.github.io/react/docs/reusable-components.html#stateless-functions, your code sample would be converted to:

import React from 'react';
import TopBar from './topBar';
import Content from './content';

function App (props) {
  return (
    <div className="app">
      <TopBar />
      <Content />
    </div>
  );
}

export default App;

Note that this updated code sample will break some other airbnb eslinting rules but those should be self-explanatory. Just posting this as a template to follow. The docs on this subject are very direct so make sure you give those a good review.

Brice Mason
  • 686
  • 5
  • 8