Skip to content
Snippets Groups Projects
Select Git revision
  • 2c554ffe9d7f210a82f5d138d4ae1085355072f4
  • main default protected
  • v5.2
  • v5.1
  • v7.1
  • v7
  • v6.2
  • v6.1
  • v6
  • v5.9
  • v5.8
  • v5.7
  • v5.6
  • v5.5
  • v5
  • v5.3
  • v4.6
  • v4.6-problem
  • v4.5
  • v4
  • v3.2
  • v3.1
22 results

person.component.jsx

Blame
  • Forked from javascript / intro-react
    3 commits behind the upstream repository.
    user avatar
    Jean-Christophe authored
    c437d698
    History
    person.component.jsx 648 B
    import { useEffect, useRef } from 'react';
    
    import '../assets/style/person.css';
    
    const Person = ( { name = 'Anonymous', age, id, started, delay, incrementAge } ) => {
       
       const timer = useRef( undefined );
    
       useEffect( () => {   
             if (started) {
                timer.current = setInterval( () =>  incrementAge( id ), delay);
             }
             return () =>  clearInterval( timer.current );                   
          }, [started, delay] );
    
       return (
          <div className="person">Here is :
             <div>name : <span>{ name }</span> </div>
             <div>age  : <span>{ age } </span>  </div>
          </div>
       );
    }
    export default Person;