score:0
you're calling the function directly. so it triggers a re-render. assign a function the onclick handler rather than calling it.
onclick={() => setproduct(e.product_id), () => { addproduct(e.product_id) }
score:0
you can't call directly setproduct directly.
onclick={() => setproduct(e.product_id), () => { addproduct(e.product_id) }
another way, simple and easy to read.
const clickhandler = (e) => {
setproduct(e.product_id);
addproduct(e.product_id);
}
<a href="#" class="btn btn-success" onclick={clickhandler} >something</a>
Source: stackoverflow.com
Related Query
- can I do many functions in one Onclick
- Can async functions be called in onClick in button react
- If you put two functions in onClick in React, only one of them will work
- How would you rewrite these 3 functions so that it can called by one function?
- How can I "mimic" a one to many relationship with react firebase cloud?
- How to call two functions in one onClick handler
- Why does only one of my functions in onClick execute?
- OnClick function cannot get value of one block's 'value' prop, but it can get the value of another block
- In JavaScript, how can one import classes and functions simply, like in python?
- Can I have one onClick function to change different state values in React-js
- How can I make a component smart enough to know about a function that could have come from one of many sources?
- How call two functions one after another onClick in reactjs. Both functions are async
- In general is it better to use one or many useEffect hooks in a single component?
- Call multiple functions onClick ReactJS
- How can one tell the version of React running at runtime in the browser?
- react Material-ui, How do I know I can use onClick for button?
- How can I animate a react.js component onclick and detect the end of the animation
- How can one extend React types to support html attributes as props?
- Can I use arrow functions instead of normal functions for React Hooks?
- Can only set one of `children` or `props.dangerouslySetInnerHTML`
- How can I expose functions to the ref using functional components?
- How to call multiple functions on the same onClick event ReactJS
- Can we pass setState as props from one component to other and change parent state from child component in React?
- When using ES6, how can an imported function be undefined in one file, and not in another?
- how to add two onClick functions in React
- How can I test functions that are provided by context using jest and react-testing-library?
- useState hook can only set one object at the time and return the other object of the same array to initial state
- React - toggle display of one component from the onClick of another component
- How can I rerender only one item in a flatlist?
- How can one prevent excess JS event handlers in React?
More Query from same tag
- React Router dynamic routing based on JS Array
- Live vertical viewport tracking not working in React
- Using Filter Function to Return React Component - Code Review
- How to prioratize onPaste over onKeyPress in Safari
- Append value to array inside dictionary (useState) react js
- React testing library not work with react router v6
- React Bootstrap: set props on component dynamically
- React component props not getting rendered inside Next.js Page
- Handling errors in useEffect when fetching data from an API
- Search box filtering does not return the searched result- React+ react-table+ filter
- Update with axios put do not work on API / React.js
- how to import Helper class in react
- Why react rerendres components even if props didn't changed?
- Missing sourcemaps in Typescript + Webpack project
- How to set state with React hooks from async fucntion return
- What is the right way to handle nested async calls using axios
- React fetching a remote API, the response is not what I expected
- I cannot get images in the images folder in react
- Set Child Component TextField's Value to Parent Components Dropdown Selection?
- Dropdown, React Router and back button
- Chakra UI : The background does not dim when the drawer opens
- Flowtype Cannot get .clientHeight because property clientHeight is missing in Node [prop-missing]
- Fetching data from the same server. What url to use?
- How can I add altmetrics badge to in ReactJS
- Nuka-carousel custom arrow button
- React-Redux reducer method errors out when executed
- I want to change the position and style of the label in the React chart
- Rendering more than 1000 markers in react-leaflet takes ages and user experience is horrible, need to improve my approach
- Does React useMemo Re-render if Dependent Object is An Array?
- React: How to make item like m2, km2 (have the number 2 in the top right of letter 'm')