Skip to content
Snippets Groups Projects
Select Git revision
  • 1f3c165699567666659c8cc6284321c52c9c6681
  • 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

star.component.jsx

Blame
  • Forked from javascript / intro-react
    Source project has a limited visibility.
    star.component.jsx 617 B
    import { useState } from 'react';
    
    import starOn from '../assets/images/star_on.png';
    import starOff from '../assets/images/star_off.png';
    
    /*
     define component Star, at first Star is off, click on component light on the star using handleClick
    */
    const Star = () => {
       const [ on, setOn ] = useState(false) ;
    
       /* onClick listener, turn the star on if not yet */
       const handleClick = () => {
          setOn(!on);
          console.log(on);
          setOn(!on);
          console.log(on);
       }
    
       return(
          <img src = { on ? starOn : starOff }
               onClick = { handleClick }
          />
       );
    
    }
    
    export default Star;