CustomHooks

1:--


import React from 'react'
import { useEffect } from 'react'
export default function UseCount(count) {
    useEffect(()=>{
        console.log('good morning');
        
        document.title="facebook.com"
        if(count>0){
          document.title=`facebook.com${count}`;
        }
          },[count])
        
}

import { ChangeCircle } from '@mui/icons-material';
import React,{useState,useEffectfrom 'react'
import UseCount from './UseCount';

export default function First() {
  const [count,setCount]=useState(0);
//call hook
UseCount(count);
  const Change=()=>{
   setCount(count+1)
  }
//   useEffect(()=>{
// console.log('good morning');

// document.title="facebook.com"
// if(count>0){
//   document.title=`facebook.com${count}`;
// }
//   },[count])
  return (
    
    <div>
      {count}
      {/* <button onClick={()=>setCount(count+1)}>click</button> */}
      <button onClick={Change}>click</button>
      </div>
  )
}

2:-- import { ChangeCircle } from '@mui/icons-material';

import React,{useState,useEffectfrom 'react'
import UseCount from './UseCount';

export default function First() {
  const [count,setCount]=useState(0);
//call hook
UseCount(count);
  const Change=()=>{
   setCount(count+1)
  }
//   useEffect(()=>{
// console.log('good morning');

// document.title="facebook.com"
// if(count>0){
//   document.title=`facebook.com${count}`;
// }
//   },[count])
  return (
    
    <div>
      {count}
      {/* <button onClick={()=>setCount(count+1)}>click</button> */}
      <button onClick={Change}>click</button>
      </div>
  )
}

Comments

Popular posts from this blog

interview questions js[ Anurag Singh ProCodrr]

reactnative_creation