【发布时间】:2021-03-22 03:27:30
【问题描述】:
如何在功能组件中调用函数,请查看下面的代码sn-p
import React from 'react';
const Users = () => {
const greeting = 'Hello Function Component!';
onUpdate = (name, age) => event => {
// .....
}
onUserChange = (name, id) => {
// Here i want to call the function onUpdate(name, age)
}
return (
<select onChange={onUserChange}>
// .....
</select>
);
};
export default Users;
请建议我在 reactjs 功能组件中调用 onUpdate(name, age) 函数。
【问题讨论】:
-
就像你在 JS 中调用任何函数一样。
onUpdate(...);。但请在函数之前添加const以避免创建全局变量。
标签: javascript reactjs