useEffect cleanup1

by istiq20

JavaScript

import React, { useState, useEffect } from 'react';

const CleanUp1 = () => {
  const [count, setCount] = useState(0);

  useEffect(() => {
    console.log("Component did mount")

    return () => {
      console.log("Compoenent unmount")
    }
  })

  return (
    <div className="functional-app">
      <h1>How to add clean up function</h1>
      <h2>Counter: {count}</h2>
      <button onClick={() => setCount(count + 1)}>
        Add Counter
      </button>
    </div>
  );
}

export default CleanUp1