我正在尝试扩展一个 React 输入组件,该组件需要输入密码,并且在其旁边的元素或元素发生特定事件之后 - 它需要切换输入的类型(type =“text/password”)。
React 如何处理这个问题?
我将其作为我的组件的类:
import { React, Component } from 'lib'
export class PasswordInput extends Component {
constructor(props, context){
super(props, context)
const { type, validate, password } = this.props
if(context.onValidate && password) {
context.onValidate(password, validate)
}
if(context.showHide && password) {
context.onValidate(password, validate)
}
}
render() {
let inputType = 'password'
return (
<div className="form">
<label htmlFor="password">{ this.props.label }</label>
<input {...this.constructor.filterProps(this.props)} type={ inputType } />
{ this.props.touched && this.props.error && <div className="error">{ this.props.error }</div> }
<button …Run Code Online (Sandbox Code Playgroud)