Skip to content

react/prefer-stateless-function with PureComponent. #1773

Closed
@ghost

Description

I'm using:

"react/prefer-stateless-function": [1, { "ignorePureComponents": true }]

but I'm also using this new Query component by react-apollo:

import React, { PureComponent } from "react";
import gql from "graphql-tag";
import { Query } from "react-apollo";

const GET_DOGS = gql`
  {
    dogs {
      id
      breed
    }
  }
`;

class DogsLove extends PureComponent {
    render() {
        return (
            <Query query={GET_DOGS}>
                {({ loading, error, data }) => {
                if (loading) return "Loading...";
                if (error) return `Error! ${error.message}`;

                return (
                    <select name="dog" onChange={onDogSelected}>
                    {data.dogs.map(dog => (
                        <option key={dog.id} value={dog.breed}>
                        {dog.breed}
                        </option>
                    ))}
                    </select>
                );
                }}
            </Query>
        )
    }
}

So, why this is a warning? (Or an error if I disable ignorePureComponents?)

I just need PureComponent because I don't need to re-render DogsLove component every time I switch Route. I need it to render just one time, the first time. Then Query component is making an observable and nothing more.

Where am I wrong?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions