day 246 — code 365

Tue 16 Aug 2016

React

Learnt more about calling and passing functions.

We can attach a function to a click event:

We need to write this:

onClick={(e) => setActive(e, index)}

Which is different to:

onClick={setActive(e, index)}

(this will immediately call the function once the browser reaches this section of the code!)

We can also call 2 methods on click

onClick={(e) => {
setActive(e, index);
setVisible(index);
}

Also using the classnames module to define conditional classes — it’s quite simple, and I could (and have) written my own version of this, but its in use elsewhere in the application, and it makes good sense to keep thing consistent and easy to use between all developers working in the code base!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.