Javascript 如何在React JS中使用函数内部的函数
如何在React JS中的函数中使用我的函数?代码如下:Javascript 如何在React JS中使用函数内部的函数,javascript,reactjs,Javascript,Reactjs,如何在React JS中的函数中使用我的函数?代码如下: function MyForm(props, ref) { fileSelectedHandler = event => { console.log(event); } return ( <div> <label htmlFor="file-icon">Upload icon</label> <input type=&qu
function MyForm(props, ref) {
fileSelectedHandler = event => {
console.log(event);
}
return (
<div>
<label htmlFor="file-icon">Upload icon</label>
<input type="file" id="file-icon" onChange={this.fileSelectedHandler}/>
</div>
)}
函数MyForm(道具,参考){
fileSelectedHandler=event=>{
console.log(事件);
}
返回(
上传图标
)}
尝试改用onChange={fileSelectedHandler}
在使用功能组件时,与基于类的组件不同,您实际上不需要将this
放在组件中以引用组件中声明的函数