React - using vars in JSX

0 votes
21 views
added Jul 2 in React by lcjr First Warrant Officer (11,970 points)
Define vars
const DraggableComponent = () => {
  const draggyBubble = 'draggy.gif';
  const draggyLink = 'https://example.com/draggylink';
  
JSX

if (timeElapsed < 100 && distanceMoved < 10) {
    window.open(draggyLink, '_blank');
} else {
  e.preventDefault();
}

<div className='offerDraggableGifBox'>
  <img className='offerDraggableGif'
    src={draggyBubble}
    alt="Draggable gif"
  />
<div className="offerDraggableGifOverlay"/>
</div>

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...