Untitled

mail@pastecode.io avatar
unknown
plain_text
10 days ago
668 B
1
Indexable
Never
import React, { useState } from 'react';

// Memoized child component
const ChildComponent = React.memo(({ value }) => {
  console.log('Child component rendered');
  return <div>Value: {value}</div>;
});

const PureComponentExample = () => {
  const [count, setCount] = useState(0);
  const [value, setValue] = useState(10);

  return (
    <div>
      <h2>React.memo Example</h2>
      <ChildComponent value={value} />
      <button onClick={() => setCount(count + 1)}>Increment Count: {count}</button>
      <button onClick={() => setValue(value + 1)}>Increment Value: {value}</button>
    </div>
  );
};

export default PureComponentExample;
Leave a Comment