Deep comparison in PureComponent question
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 11.8k
- Forks
- 7.9k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 11
Description
Hello team,
We have a base class for React components that we're beginning to use. It's like PureComponent but does deep comparison of JSON-like values (just objects, arrays, and primitives). The purpose is to avoid re-renders when inputs haven't changed, even when objects/arrays were reconstructed.
import React from 'react';
import { compareObj } from './deepCompare';
export default class PureDeepComponent extends React.Component {
shouldComponentUpdate(newProps, newState) {
return !(compareObj(this.props, newProps) && compareObj(this.state, newState));
}
}
I was surprised that something like this wasn't included in React, and I'm wondering what the team's thoughts are -- was there a good reason for not doing something like this?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file, test, or entry point is identified. Start by reviewing the PureComponent and shouldComponentUpdate behavior described in the issue, then determine whether the desired outcome is a React API feature or documentation; the issue is not complete until that scope and acceptance criteria are agreed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 18/100