score:1
if you want clickable child nodes to not trigger parent node (event-bubbling) then you can use event.stoppropagation().
here is a small running example:
class app extends react.component {
anchor = () => console.log("anchor");
button = e => {
e.stoppropagation();
console.log("button");
};
render() {
return (
<div>
<div>
<a
onclick={this.anchor}
style={{ border: "1px solid", padding: "15px" }}
>
i'm an anchor
<button onclick={this.button}>button</button>
</a>
</div>
</div>
);
}
}
const root = document.getelementbyid("root");
reactdom.render(<app />, root);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="root" />
score:0
what are you trying to achieve exactly?
if you are trying to update state or complete some action from the button click you can do this from the function you defined:
addtofavourites = () => {
this.setstate({"somestateproperty": "update"})
}
if you are trying to update state or click the tag by clicking the star i would suggest adding some additional detail as to what you are trying to do. if you want to update styling or something then you should be able to update state of torender on click of the star.
Source: stackoverflow.com
Related Query
- How to make one table record editable on button click in React when the table record is mapped?
- Scroll down the page to another React component on a button click
- How to get the time in seconds after click on submit button using React Count Down Timer
- How do I call a function on button click to listen for another mouse click in React Hooks?
- how to change background color when I click the button using react hooks
- React Js how to jump whole pages to other pages when click on the navigation button
- How to redirect another page after button on click method react js
- How to set focus on child component's input on a button click in the parent in React Hooks
- How to blur the background after click on the button in react js
- How to click at button at the another button in React?
- How to destroy and reinitialize component in react on Button click in another component
- How can strike a post out when i click the complete button in React
- How change the styling of dynamically generated JSX via a button click in React Native
- How do I target and change the style of a different element when I click a button in react
- How to test the child component render text after the button on the parent component click with react testing library?
- How to hide a button when I click the button in react using functional components
- I have buttons and a textbook in my React App, How do I make the click of the button trigger text input?
- How to make a button click another button from different components in React
- How to pass data from child to parent on click of a button in the parent React
- How to call a function in one React component by button click in another component
- How to test button that on click renders html element within the same component in React testing library, Jest?
- how do i toggle the div when click outside of the button in react js?
- How to redirect to another page when the button is clicked on React js?
- How to make the selenium web driver click on a button which is inside react spotlight (React Joyride)?
- How do I add a transition to my navbar menu in react when I click the toggle button
- How to change button background color when I click the button in React using Hooks
- How to display different value from the api on radio button click in react js.?
- How to click a button into a list array items only effect the related item using React hooks
- How to pass the value outside of the arrary while click on button in React js , React slick carousel?
- How to pass in a react component into another react component to transclude the first component's content?
More Query from same tag
- Not able to override the default color of the material ui appbar
- Display images with a loop in a React component
- How to add an option by clicking button on a page and have the option added to select tag in another page?
- ReactJS auth not working, redirect to login page fails
- Socket IO works fine on local machine but doesn't work on Heroku
- ReactJS: replacing object from array with new value replaces whole array
- How to persist state across react router transitions
- Initializing useContext Types for Custom Hook
- Change background color FullCalender react
- React Router: TypeError Cannot read properties of undefined (reading 'originalPositionFor')
- React - My user interface does not re-render properly when my React hook is updated
- How can I fetch content from a single page throught Contentful API in a NextJS website?
- Is there something blocking a map method inside of a for loop?
- load and play another song when button is clicked
- Change colour of nextjs - tailwind component based on prop
- Array.prototype.map() expects a value to be returned at the end of arrow function
- Next Auth "Credentials" redirection when throwing error on custom login page
- GraphQL error: Cannot query field 'mutation_name' on type 'Mutation'
- .reduce in lodash fucntionality
- Passing username and family name from google login
- this.state.persons.map is not a function
- How to call functions in same level components in reactjs?
- "Cannot read property 'nationalCode' of undefined" error in redux-form
- Stop an update when a condition is met (React tic-tac-toe)
- React Checkbox Does Not Update
- Restoring a React Context to its Default State
- Ant Design TreeSelect map data from API to title value keys
- Is there any mean to render an object in a React div?
- How to delay file import in React?
- getUserConfirmation Prompt React Router with History Redirect