react image trick1

Michael Minchang Kim·2020년 5월 31일
0

wecode

목록 보기
21/22
post-custom-banner

when you want to switch between two images depending on an action you can use a boolean as the value of a state to see what image will be displayed

 <button
    onClick={() => this.changeShape("two")}
    type="checkbox"
    className="checkbox"
 >
    <img src={this.state.two === false ? click : clicked} />
 </button>

Another trick related to this is passing a string into a function. By doing this you can use the same function and apply it to multiple different states.

profile
Soon to be the world's Best programmer ;)

0개의 댓글