From 4fa825110fa07bed8ed6046807b86c77add54b16 Mon Sep 17 00:00:00 2001 From: Lenny Sirivong Date: Mon, 11 Mar 2019 16:25:58 -0400 Subject: [PATCH] Handle onClick prop explicitly --- example/src/pages/index.js | 7 +++++++ example/src/pages/page-2.js | 7 +++++++ src/components/TransitionLink.js | 9 +++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/example/src/pages/index.js b/example/src/pages/index.js index 69eba39..0adaef8 100644 --- a/example/src/pages/index.js +++ b/example/src/pages/index.js @@ -120,6 +120,13 @@ class Index extends Component { and give us a dark theme when we get there.
+ console.log('Link clicked')} + > + Go to page 2 normally (with an `onClick`) + +
diff --git a/example/src/pages/page-2.js b/example/src/pages/page-2.js index 1fba7e2..e1f979c 100644 --- a/example/src/pages/page-2.js +++ b/example/src/pages/page-2.js @@ -137,6 +137,13 @@ export default class SecondPage extends Component { 👉 +
+ console.log('Link clicked')} + > + Go home normally (with an `onClick`) +
{ return ( @@ -22,7 +23,7 @@ const TransitionLink = ({ activeStyle={activeStyle} style={style} className={className} - onClick={event => + onClick={event => { triggerTransition({ event, to, @@ -30,7 +31,11 @@ const TransitionLink = ({ entry, ...context }) - } + + if (typeof onClick === 'function') { + onClick(event) + } + }} to={to} // use gatsby link so prefetching still happens. this is prevent defaulted in triggertransition {...rest} >