Legacy React addon for performing shallow comparison of props and state to optimize component rendering performance
Overall
score
99%
Build a React component that efficiently displays user information with performance optimizations to prevent unnecessary re-renders.
Create a UserCard component that displays user information and only re-renders when its props or state actually change. The component should:
Props:
name (string): User's full nameemail (string): User's email addressstatus (string): User's current status (e.g., "active", "inactive")State:
interactionCount (number): Tracks how many times the user has clicked the interaction buttonBehavior:
@generates
import React from "react";
/**
* A performance-optimized component that displays user information
* and tracks user interactions while preventing unnecessary re-renders.
*/
class UserCard extends React.Component {
constructor(props) {
super(props);
this.state = {
interactionCount: 0
};
}
// Implement performance optimization here
handleInteraction = () => {
this.setState(prevState => ({
interactionCount: prevState.interactionCount + 1
}));
};
render() {
const { name, email, status } = this.props;
const { interactionCount } = this.state;
return (
<div className="user-card">
<h3>{name}</h3>
<p>Email: {email}</p>
<p>Status: {status}</p>
<p>Interactions: {interactionCount}</p>
<button onClick={this.handleInteraction}>Interact</button>
</div>
);
}
}
export default UserCard;Provides shallow comparison utilities for React component optimization.
React library for building user interfaces.
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