简体   繁体   English

简单的事件监听器 reactjs 不起作用

[英]simple event listener reactjs not working

i am new to react .我是新来的反应。 when i run this code and type somehting in the input nothing appear in the console .当我运行此代码并在输入中键入 somehting 时,控制台中没有任何显示。 what is wrong怎么了

import "./styles.css";
import React from "react";
import ReactDOM from "react-dom";
const Copyinput = (e) => {
  console.log("wow");
};

export default function App() {
  return (
    <div className="App">
      <input type={Text} onchange={Copyinput}></input>
    </div>
  );
}

React events are supposed to be camelCase : onChange . React 事件应该是camelCase : onChange

Also, I hope your Text is a variable.另外,我希望你的Text是一个变量。 Otherwise, you can pass it as a string or declare it above your return :否则,您可以将其作为字符串传递或在return上方声明:

<input type="text" onChange={Copyinput}></input>

React events are camel case so onchange should be onChange. React 事件是驼峰式的,所以 onchange 应该是 onChange。 Your attribute type should not be in curly braces.您的属性类型不应包含在花括号中。 It should be string应该是字符串

This will work for you:这对你有用:

<input type="text" onChange={Copyinput}></input>

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

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