Legacy React addon for performing shallow comparison of props and state to optimize component rendering performance
Overall
score
99%
Build a utility function that compares React component props to determine if a component should re-render. The function should handle various types of property configurations and provide accurate comparison results.
Your implementation should:
true if the component should update (props differ), false otherwiseNaN, +0 vs -0, null, and undefined correctly@generates
/**
* Compares current props with next props to determine if update is needed.
*
* @param {Object} instance - Component instance with current props
* @param {Object} nextProps - New props to compare against
* @returns {boolean} - true if component should update, false otherwise
*/
function shouldUpdate(instance, nextProps) {
// IMPLEMENTATION HERE
}
module.exports = { shouldUpdate };{a: 1, b: 2} and nextProps {a: 1, b: 2}, shouldUpdate returns false @test{a: 1, b: 2} and nextProps {a: 1, b: 3}, shouldUpdate returns true @test{visible: true} and a non-enumerable property, and nextProps with only {visible: true}, shouldUpdate returns false (non-enumerable properties are ignored) @test{x: 1} that has inherited properties from its prototype, and nextProps {x: 1}, shouldUpdate returns false (inherited properties are ignored) @testProvides shallow comparison functionality for React component optimization.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-react-addons-shallow-comparedocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10