小编Zer*_*er0的帖子

如何从钩子反应组件获取TextField(Material-UI)值?

我使用 Material-UI 和 React,有如下组件:

const UserDetail = (props: ListDetailProps) => {
    const oldpassword = useRef<TextFieldProps>(null);
    const newpassword = useRef<TextFieldProps>(null);
    const againpassword = useRef<TextFieldProps>(null);
    const handlePasswordChange = async () => {
        console.log(newpassword.current?.value)    //expect the password value but undefined get
        console.log(againpassword.current?.value)  //expect the password value but undefined get
    }
    return (<>
        <p>old password: <TextField ref={oldpassword} label="old password" type="password" /></p>
        <p>new password: <TextField ref={newpassword} label="new password" type="password" /></p>
        <p>new password: <TextField ref={againpassword} label="new password again" type="password" /></p>
        <button onClick={handlePasswordChange}>submit</button>
    </>
    )
}
Run Code Online (Sandbox Code Playgroud)

我想获取 …

typescript reactjs material-ui react-hooks use-ref

3
推荐指数
1
解决办法
5625
查看次数

C# 通过名称获取对象属性

在其他语言中,例如 JavaScript,我可以使用:

const obj = { a: 5 };
obj["a"] //returns 5
Run Code Online (Sandbox Code Playgroud)

如果 C# 中的名称以字符串形式给出,是否可以获取对象属性?我不想要一棵巨大的 if/else 树

c#

2
推荐指数
1
解决办法
6796
查看次数

标签 统计

c# ×1

material-ui ×1

react-hooks ×1

reactjs ×1

typescript ×1

use-ref ×1