DEV Community

Helder Burato Berto
Helder Burato Berto

Posted on

6 1

🔥 Quick Tip: How to create a "PureComponent" as a functional way

On this simple trick, I'll show you how to create a PureComponent as a functional way with React.memo.

// CLASS BASED - OLD WAY
class Button extends React.PureComponent {
  render() {
    const { text } = this.props;
    return (
      <button type="button">{text}</button>
    )
  }
};

// FUNCTIONAL

// With Function
function Button({ text }) {
  return <button type="button">{text}</button>;
};
export default React.memo(Button);

// With Arrow Function
const Button = React.memo(({ text }) => <button type="button">{text}</button>);
export default Button;
Enter fullscreen mode Exit fullscreen mode

Did you like it? Comment, share! ✨

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more