JavaScript HTML event handler vs React event handler html event handler attributes,html event handler javascript,html event

I would like to ask a question about event handlers when used in HTML and React.

In the book Javascript and Jquery written by Jon Duckett, the author mentioned that using HTML event handler attribute is considered bad practice for instance something like the following:

<button onClick="hide()">click me</button>

But recently I am starting to learn React and when a component is defined, there are many examples of event handlers used as an attribute and it seems common to do so, not getting criticism for doing so,

<button onClick={doSomething}>
  xxxyyyzzz
</button>

Is there a reason to this? is it because this is the only way to bind a event handler in React?, from the way I see it React is essentially building the component element via HTML but uses the event handler attribute to assign an event to it, so why is React bringing back a concept that is considered bad practice?

Answer:1

Why are inline event listeners bad practice?

HTML describes the content and structure of a document, CSS describes the appearance and JavaScript is about the logic or behavior. These things should be kept separately. HTML and JavaScript code shouldn't be mixed. Your example for that was:

<button onClick="hide()">click me</button>

This, however, does not apply to React: we don't have one HTML file. Instead, we have modularized components, which have their own structure, style and behavior.

In React, we don't want the separation of presentation and logic, but self-contained components. That's what sets it apart from an application using just "Vanilla JavaScript" / the DOM API.

Answer:2

Hello im trying to use Math.min but i am getting NaN as a result, this is the code. method using Math.min method() { var DeltaPrueba = this._markerService.getDeltasRx1(); console.log(DeltaPrueba); ...

Hello im trying to use Math.min but i am getting NaN as a result, this is the code. method using Math.min method() { var DeltaPrueba = this._markerService.getDeltasRx1(); console.log(DeltaPrueba); ...

I have two types of Strings like the following : 78:24207 PERF keytouchListAction ProtocolSelect 04.00 : 1502876877199 1502876879180 or 78:27247 PERF create tab state : 1502876879180 I'm looking ...

I have two types of Strings like the following : 78:24207 PERF keytouchListAction ProtocolSelect 04.00 : 1502876877199 1502876879180 or 78:27247 PERF create tab state : 1502876879180 I'm looking ...

Unfortunately I did not find any existing solution for my problem on stackoverflow. So, can someone help. I want to get the text of an html-element. I tried this: var element = driver.findElement(...

Unfortunately I did not find any existing solution for my problem on stackoverflow. So, can someone help. I want to get the text of an html-element. I tried this: var element = driver.findElement(...

  1. text html element
  2. text html element center
  3. html text element with id
  4. html text element color
  5. html text element attributes
  6. html text element width
  7. html text element value
  8. html text element line break
  9. html text element properties
  10. html text element tag
  11. html text element new line
  12. html text element dom
  13. html text element border
  14. html text element bold
  15. html text element font
  16. html text element input
  17. html text element code
  18. text element html div
  19. get text html element javascript
  20. set text html element

could you please tell me how to send data from one view to another view .Actually I have one input field and button on my main screen .I want to send data of input text from one screen to another ...

could you please tell me how to send data from one view to another view .Actually I have one input field and button on my main screen .I want to send data of input text from one screen to another ...

  1. send input text to javascript function
  2. send text input javascript
  3. javascript send input text value
  4. adb send text input
  5. html send text input
  6. jquery send text input
  7. input text send