简体   繁体   English

在 React.createElement 中将 `onSubmit` 作为道具传递

[英]passing `onSubmit` as a prop in React.createElement

I have the following code:我有以下代码:

data = React.createElement(f, {onsubmit: a}, div.fields.map((d, i) => {
  let thisInput
  if (d.placeholder) {thisInput = React.createElement(d.format, {placeholder: d.placeholder, className: "captureEmail"})}
  if (d.value) {thisInput = React.createElement(d.format, {className: "btn"}, d.value)}
  return thisInput
}))

Particularly, I'm looking at {onsubmit: a} in the first line.特别是,我正在查看第一行中的{onsubmit: a} I can pass className if I'd like but the onsubmit or onclick won't end up in the HTML.如果我愿意,我可以传递className ,但onsubmitonclick不会出现在 HTML 中。 Is that a limitation in React?这是 React 的限制吗?

In React, event names are camel cased.在 React 中,事件名称是驼峰式的。 The compiler will covert it back to all lower case when constructing the compiled vanilla JS.编译器在构建已编译的 vanilla JS 时会将其转换为全部小写。 To make it work, pass it the onsubmit event handler as onSubmit and the onclick event handler as onClick.要使其工作,请将 onsubmit 事件处理程序作为 onSubmit 传递,并将 onclick 事件处理程序作为 onClick 传递。

data = React.createElement(f, {onSubmit: a}, div.fields.map((d, i) => {
  let thisInput
  if (d.placeholder) {thisInput = React.createElement(d.format, {placeholder: d.placeholder, className: "captureEmail"})}
  if (d.value) {thisInput = React.createElement(d.format, {className: "btn", value: d.value})}
  return thisInput
}))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM