css
.success {
background-color: lightgreen;
}
.failure {
background-color: lightcoral;
}
js
import React, { Component } from 'react';
import './VaildationSample.css';
export class VaildationSample extends Component {
state = {
password: '',
clicked: false,
vaildated: false,
};
handleChange = (e) => {
this.setState({
password: e.target.value,
});
};
handleButtonClick = () => {
this.setState({
clicked: true,
vaildated: this.state.password === '0000',
});
};
render() {
return (
<div>
<input
type="password"
value={this.state.password}
onChange={this.handleChange}
className={
this.state.clicked
? this.state.vaildated
? 'success'
: 'failure'
: ''
}
></input>
<button onClick={this.handleButtonClick}>검증하기.........</button>
</div>
);
}
}
export default VaildationSample;
'React.js' 카테고리의 다른 글
useState + axios (then안에서 많은걸 하려고 하지 말자) (0) | 2023.08.09 |
---|---|
useState 사용 시 화살표함수를 사용해야 하는 이유 (0) | 2023.04.09 |
useState 기초 (0) | 2023.04.04 |
댓글