02|カテゴリメニューナビゲーション
14393 ワード
overview ✨
https://stackoverflow.com/questions/26069238/call-multiple-functions-onclick-reactjs
私があなたに書いたコード
1つのonclickイベントで2つのコールバック関数を呼び出す
https://stackoverflow.com/questions/26069238/call-multiple-functions-onclick-reactjs
<span
// onClick={
// (() => this.props.handleCategory('category'),
// () => this.handleCategoryBorder('categorySelected'))
// }
onClick={() => {
this.props.handleCategory('category');
this.handleCategoryBorder('categorySelected');
}}
className={
this.state.currentCategory === 'categorySelected'
? 'selected'
: 'none'
}
>
Category
</span>
<span
// onClick={
// (() => this.props.handleCategory('healthGoal'),
// () => this.handleCategoryBorder('healthGoalSelected'))
// }
onClick={() => {
this.props.handleCategory('healthGoal');
this.handleCategoryBorder('healthGoalSelected');
}}
className={
this.state.currentCategory === 'healthGoalSelected'
? 'selected'
: 'none'
}
>
Health Goal
</span>
import React, { Component } from 'react';
import './CategoryNav.scss';
class CategoryNav extends Component {
constructor() {
super();
this.state = {
currentCategory: 'categorySelected',
};
}
handleCategoryBorder = category => {
this.setState({ currentCategory: category });
};
render() {
return (
<nav className="CategoryNav">
<div className={`nav-container ${this.state.currentCategory}`}>
<span>Shop by :</span>
<span
// onClick={
// (() => this.props.handleCategory('category'),
// () => this.handleCategoryBorder('categorySelected'))
// }
onClick={() => {
this.props.handleCategory('category');
this.handleCategoryBorder('categorySelected');
}}
className={
this.state.currentCategory === 'categorySelected'
? 'selected'
: 'none'
}
>
Category
</span>
<span
// onClick={
// (() => this.props.handleCategory('healthGoal'),
// () => this.handleCategoryBorder('healthGoalSelected'))
// }
onClick={() => {
this.props.handleCategory('healthGoal');
this.handleCategoryBorder('healthGoalSelected');
}}
className={
this.state.currentCategory === 'healthGoalSelected'
? 'selected'
: 'none'
}
>
Health Goal
</span>
</div>
</nav>
);
}
}
export default CategoryNav;
Reference
この問題について(02|カテゴリメニューナビゲーション), 我々は、より多くの情報をここで見つけました https://velog.io/@saemsol/02-카테고리-메뉴-네이게이션テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol