Legacy React addon for performing shallow comparison of props and state to optimize component rendering performance
Overall
score
99%
Build a React component that displays user profile information and optimizes rendering performance by preventing unnecessary re-renders when props or state haven't changed.
Create a class-based React component named UserProfile that:
Accepts the following props:
userId (number): The user's IDname (string): The user's nameemail (string): The user's email addressavatar (string): URL to the user's avatar imageMaintains internal state for:
isExpanded (boolean): Whether the profile is in expanded or collapsed viewImplements performance optimization to prevent unnecessary re-renders when props and state haven't changed
Renders:
When a UserProfile component receives the same props and state values it already has, it should not re-render @test
When a UserProfile component receives different prop values (e.g., name changes from "Alice" to "Bob"), it should re-render @test
When a UserProfile component's state changes (e.g., isExpanded toggles from false to true), it should re-render @test
When a UserProfile component receives props with the same values but NaN appears in a prop, it should correctly handle the NaN comparison @test
@generates
import React from 'react';
/**
* A performance-optimized user profile component that prevents unnecessary re-renders.
*/
class UserProfile extends React.Component {
constructor(props) {
// Initialize state
}
shouldComponentUpdate(nextProps, nextState) {
// Implement performance optimization here
}
toggleExpanded() {
// Toggle the isExpanded state
}
render() {
// Render the component based on props and state
}
}
export default UserProfile;Provides the React library for building UI components.
Provides shallow comparison functionality for optimizing component rendering performance.
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