FAQ: Components and Advanced JSX - Use an Event Listener in a Component

This community-built FAQ covers the “Use an Event Listener in a Component” exercise from the lesson “Components and Advanced JSX”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Learn ReactJS: Part I

FAQs on the exercise Use an Event Listener in a Component

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

How come in this excericse part #2 where did “” come from? Shouldn’t it be “” or does this not matter if it’s cap or not?

In exercise #6, why we don’t need to add parenthesis after the method myFunc? Like this: this.myFunc()

4 Likes

Same question as xinxin63. I understand getters don’t need (), but why are we not adding those in this exercise?

1 Like

I also have the same question as xinxin63 and michiyouki13

1 Like

If you use, this.func() ,Function gets executed before it is called.
Here is a clear example:
In the exercise “Use an Event Listener in a Component” , you see a function scream(). If you use it as this.scream(), Event handler does not wait to listen to the event, it executes as soon as the program runs.

I hope this answers your questions.
But I am still wondering how to pass parameters in that case

4 Likes

For me, nothing rendered on the right side of the screen for several of the exercises in this lesson. It tells me that I’m doing them correctly, but I don’t see anything, and I’m not sure how to fix it. Did anyone else have this problem?

By this time I know you will be very far in your code journey but am replying in the case of anyone else getting this error.

have you got…

import React from 'react';
import ReactDOM from 'react-dom';

At the top of your code? The exercises will still complete without this code and without this code nothing will be rendered

2 Likes

Thank you for the reply – I believe that was the issue.

1 Like