Ad
How Can I Chain Functions Together In React
I'd like to chain the two functions used below together to improve the experience of our mobile users. First the updateSelectedValue
function should be called, then the handleAddToCart
function. The below code works for desktop users, but not for mobile users:
<span
className="optionValue"
key={optionValue}
onClick={this.handleAddToCart}
onMouseEnter={() => this.props.updateSelectedValue(optionValue)}
>
{optionValue}
</span>
Ad
Answer
You could handle both functions in the onClick
event:
<span
className="optionValue"
key={optionValue}
onClick={() => {
this.props.updateSelectedValue(optionValue);
this.handleAddToCart();
}}
>
{optionValue}
</span>
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad