PF
Size: a a a
PF
NT
VS
import React, {Component} from "react";
export default class Header extends Component {
constructor(props) {
super(props);
this.onClick = this.onClick.bind(this);
}
state = {
ariaExpanded: "false"
}
onClick = (e) => {
console.log(e)
this.setState({
ariaExpanded: this.state.ariaExpanded == "false" ? "true" : "false",
});
}
render(){
return (<div aria-expanded={this.state.ariaExpanded} onClick={this.onClick}> test </div>)
}
}
NT
PF
꧁岡
import React, {Component} from "react";
export default class Header extends Component {
constructor(props) {
super(props);
this.onClick = this.onClick.bind(this);
}
state = {
ariaExpanded: "false"
}
onClick = (e) => {
console.log(e)
this.setState({
ariaExpanded: this.state.ariaExpanded == "false" ? "true" : "false",
});
}
render(){
return (<div aria-expanded={this.state.ariaExpanded} onClick={this.onClick}> test </div>)
}
}
NT
NT
PF
NT
PF
NT
PF
NT
ariaExpanded: false
...
if (ariaExpanded === false) {
ariaExpanded = true;
}
...
и только потом мы юзаем наши адекватно хранящиеся данные в компоненте
...
<button
aria-expanded={ariaExpanded ? 'true' : 'false'}
/>
NT
PF
NT
PF
PF
NT