Home > Mobile >  React / Is it possible to return an html tag with an event function?
React / Is it possible to return an html tag with an event function?

Time:09-04

Hello

I would like to display information during a MouseOver. But it seems it is not the right method to use :

 return (
        <div className="item" key={i}
          onm ouseOver = {(e) => {
            return (<div className="prompt">{variable}</div>)
          }}

What would be the correct way ?

CodePudding user response:

const [showElement, setShowElement] = useState(false);

return (
  <div className="item" key={i}
    onm ouseOver = {(e) => {
      setShowElement(true)
    }}
  >
   {showElement && <div className="prompt">{variable}</div>
  </div>
)
  • Related