기본적으로 이미지를 숨기려고하고 있는데, 엘리먼트가 올려 졌을 때만 표시하려고합니다. 나는 기본 상태 등을 설정할 수있었습니다. 유일한 문제는 이미지를 보여 주거나 숨길 수있는 if 문을 만드는 것입니다. 상태가 true로 설정되어 있으면 반응 쇼 이미지
이
는 구성 요소입니다 : 내가 몇 가지를 시도했습니다import React from 'react';
import { Link } from 'react-router';
import Eyecon from '../../static/eye.svg';
class Item extends React.Component {
constructor(props) {
super(props);
this.displayName = 'Item';
this.handleHover = this.handleHover.bind(this);
this.state = {
hover: false
};
}
mouseOver() {
this.state.hover = true;
}
mouseOut() {
this.state.hover = false;
}
handleHover() {
console.log("hover");
}
render() {
const { item, i } = this.props;
return (
<div className="grid-box">
<img src={Eyecon}/>
</div>
)
}
}
export default Item;
뿐만 아니라 가장 좋은 방법이 무엇인지보고 싶어요. 시간에 대한
덕분에
나는 반응 비교적 새로운 해요하지만 난 당신이 할 수 있다고 생각 : state' 당신이'이를 호출하여 직접 수정해서는 안 즉, 불변 '하는 것이 {this.state.hover && } – bdc
노트 .state.hover = true'. 대신에 this.setState ({hover : true}) – Hamms