<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kriyanshi Shah</title>
    <description>The latest articles on DEV Community by Kriyanshi Shah (@kriyanshishah).</description>
    <link>https://dev.to/kriyanshishah</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F662899%2F6e366723-0040-438e-a731-b680f00923d6.jpeg</url>
      <title>DEV Community: Kriyanshi Shah</title>
      <link>https://dev.to/kriyanshishah</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kriyanshishah"/>
    <language>en</language>
    <item>
      <title>How to change the image on hover using JSX.</title>
      <dc:creator>Kriyanshi Shah</dc:creator>
      <pubDate>Sat, 25 Feb 2023 14:29:37 +0000</pubDate>
      <link>https://dev.to/kriyanshishah/how-to-change-the-image-on-hover-using-jsx-3k02</link>
      <guid>https://dev.to/kriyanshishah/how-to-change-the-image-on-hover-using-jsx-3k02</guid>
      <description>&lt;p&gt;I came across this problem while working for the display part of the e-commerce type project. So I thought it to share it with everyone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pre-requisite&lt;/strong&gt;: React and JavaScript Basics.&lt;/p&gt;

&lt;p&gt;When you want to change the image on hover and you want to do that by doing some change in JSX. Good news - You can do it!!&lt;/p&gt;

&lt;p&gt;So here the simple logic is to use the onMouseOver and onMouseLeave events and change the src of the image in the JSX on the event of onMouseOver on the card. And change the src back to the original on the event on onMouseOut.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div className="card"&amp;gt;
    &amp;lt;img  src="https://image.ibb.co/b8UJBc/administration_architecture_big_ben_221166.jpg"
        onMouseOver={(e) =&amp;gt; (
            e.currentTarget.src = "https://image.ibb.co/mmyvrc/anniversary_balloons_birthday_68369.jpg"
            )}
        onMouseLeave={(e) =&amp;gt; (
            e.currentTarget.src = "https://image.ibb.co/b8UJBc/administration_architecture_big_ben_221166.jpg"
            )}
    /&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the codepen link for the same: &lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/kriyanshishah/embed/ExegQqN?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Here, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;onMouseOver&lt;/strong&gt; - This event occurs when the mouse pointer enters an element.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;onMouseOut&lt;/strong&gt; - This event occurs when the mouse pointer moves out from the element.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using this simple logic we can eliminate writing common CSS. &lt;br&gt;
And, this is also helpful if the image is coming from backend.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed reading this article.&lt;/p&gt;

&lt;p&gt;Happy learning.✨&lt;/p&gt;

</description>
      <category>requestforpost</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
