React. problem with understanding function makeDoggy


Hello guys,
I don't understand this piece of code.
Can you help me?
What does function makeDoggy mean.How did it work.I click on image and get another picture.
P.s (sry for my english)

var React = require('react');
var ReactDOM = require('react-dom');

function makeDoggy (e) {
// Call this extremely useful function on an .
// The will become a picture of a doggy.'src', '');'alt', 'doggy');

var kitty = (
<img onClick={makeDoggy}
alt="kitty" />

ReactDOM.render(kitty, document.getElementById('app'));


When the img is clicked, makeDoggy takes that event of the click and gets the target (The img tag is the target since is what had the onClick handler and is what was clicked on) . It takes the img and sets it's src attribute to the new image link (changing the image I assume) and then it changes the alt attribute of the image tag. The first two lines of this code are just importing the React and ReactDOM packages.

Hope that helps :slight_smile: .


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.