Untitled

 avatar
unknown
plain_text
a year ago
668 B
4
Indexable
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;
Editor is loading...
Leave a Comment