Ad
Can I Safely Use Both The "to" And "onClick" Props On A React Router Link?
I'd love to keep the benefits of using the default routing mechanism via the to
prop, but also add additional logging logic for when the link gets clicked.
Ad
Answer
What logic do you want to achieve? And what's stopping you from adding onClick
handler to Link
component?
<Link to="/" onClick={event => { alert('home') }}>Home</Link>
Another possible option would be to Link
to another component where you could put whatever logic inside the lifecycle method like componentDidMount()
.
Answering your question, there is a support for onClick
event in the source code. So I guess it's totally fine.
Ad
source: stackoverflow.com
Related Questions
- → Import statement and Babel
- → should I choose reactjs+f7 or f7+vue.js?
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → .tsx webpack compile fails: Unexpected token <
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → React Native with visual studio 2015 IDE
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
- → How do I determine if a new ReactJS session and/or Browser session has started?
- → Alt @decorators in React-Native
- → How to dynamically add class to parent div of focused input field?
Ad