You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -21,7 +23,7 @@ Below is a list of ReactJS interview questions and answers.
21
23
|10 |[What is the difference between state and props?](#what-is-the-difference-between-state-and-props)|
22
24
|11 |[Why should not we update the state directly?](#why-should-not-we-update-the-state-directly)|
23
25
|12 | [What is the purpose of callback function as an argument of setState?](#what-is-the-purpose-of-callback-function-as-an-argument-of-setstate)
24
-
|13 |[What is the difference between HTML and React event handling?](#what-is-the-difference-between-html-and-react-event-handling)|
26
+
|13 |[What is the difference of event handling between HTML and React?](#what-is-the-difference-of--event-handling-between-html-and-react)|
25
27
|14 |[How to bind methods or event handlers in JSX callbacks?](#how-to-bind-methods-or-event-handlers-in-jsx-callbacks)|
26
28
|15 |[How to pass a parameter to an event handler or callback?](#how-to-pass-a-parameter-to-an-event-handler-or-callback)|
27
29
|16 |[What are synthetic events in ReactJS?](#what-are-synthetic-events-in-reactjs)|
@@ -391,18 +393,18 @@ Instead use setState() method. It schedules an update to a component’s state o
391
393
392
394
12.### What is the purpose of callback function as an argument of setState?
393
395
The callback function is invoked when setState finished and the component gets rendered. Since setState is **asynchronous** the callback function is used for any post action.
394
-
**Note:** It is recommended to use lifecycle method rather this callback function.
395
396
```
396
397
setState({name: 'sudheer'}, () => console.log('The name has updated and component re-rendered'));
397
398
```
398
-
13.### What is the difference between HTML and React event handling?
399
-
Below are the few differences between HTML and React event handling,
399
+
**Note:** It is recommended to use lifecycle method rather this callback function.
400
+
13.### What is the difference of event handling between HTML and React?
401
+
Below are the few differences of event handling between HTML and React,
400
402
1. In HTML, the event name should be in lowercase.
401
403
```
402
404
<button onclick="activateLasers()">
403
405
```
404
406
405
-
Whereas in ReactJS it follows camelCase convention,
407
+
Whereas in ReactJS it follows camelCase convention,
406
408
407
409
```
408
410
<button onClick={activateLasers}>
@@ -414,7 +416,7 @@ Whereas in ReactJS it follows camelCase convention,
414
416
<a href="#" onclick="console.log('The link was clicked.'); return false"/>
415
417
```
416
418
417
-
3. Whereas in ReactJS you must call preventDefault explicitly,
419
+
3. Whereas in ReactJS you must call preventDefault method explicitly,
418
420
419
421
```
420
422
function handleClick(e) {
@@ -425,11 +427,11 @@ Whereas in ReactJS it follows camelCase convention,
425
427
426
428
14.### How to bind methods or event handlers in JSX callbacks?
427
429
**(Or)**
428
-
### How to use this in JSX callbacks?
430
+
### How to use this keyword in JSX callbacks?
429
431
430
432
There are 3 possible ways to achieve,
431
433
432
-
1.**Binding in Constructor:** In JavaScript classes, the methods are not bound by default. The same thing applies for ReactJS event handlers defined as class methods. Normally we bind them in constructor as follows,
434
+
1.**Binding in Constructor:** In JavaScript classes, the methods are not bound by default. The same thing applies for ReactJS event handlers defined as class methods. Normally, we bind them in constructor as follows,
433
435
```
434
436
constructor(props) {
435
437
super(props);
@@ -464,15 +466,15 @@ There are 3 possible ways to achieve,
464
466
465
467
You can use an arrow function to wrap around an event handler and pass parameters:
466
468
467
-
```
469
+
```javascript
468
470
<button onClick={() =>this.handleClick(id)} />
469
471
```
470
-
This is equivalent to calling .bind as below,
471
-
```
472
+
This is equivalent to using **bind** method as below,
SyntheticEvent is a cross-browser wrapper around the browser's native event. It's API is same as the browser's native event, including stopPropagation() and preventDefault(), except the events work identically across all browsers.
477
+
**SyntheticEvent** is a cross-browser wrapper around the browser's native event. It's API is same as the browser's native event, including *stopPropagation()* and *preventDefault()*, except the events work identically across all browsers.
0 commit comments