react/prefer-stateless-function with PureComponent.
See original GitHub issueI’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?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:15 (5 by maintainers)
Top Results From Across the Web
eslint-plugin-react/prefer-stateless-function.md at master
Enforce stateless components to be written as a pure function ( react/prefer-stateless-function ) Stateless functional components are simpler than class based ...
Read more >Component should be written as a pure function (react prefer ...
Whenever you don't need state of lifecycle methods, you should write your component as a stateless function, as stateless components are in ...
Read more >What are React pure functional components? - LogRocket Blog
A React component is considered pure if it renders the same output for the same state and props. For this type of class...
Read more >eslint-plugin-react-prefer-function-component - npm
eslint-plugin-react/prefer-stateless-function allows class components that implement any methods or properties other than render .
Read more >Component should be written as a pure function (react prefer ...
It will work for sure. Write your component as a stateless function: export myComponent = () => { //stuff here }; There are...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have the same problem.
ignorePureComponents: true
doesn’t seem to do anything.Doesn’t matter if I extend
PureComponent
orReact.PureComponent
.This bug need some attention 😃