jxnblk / mdx-deck

♠️ React MDX-based presentation decks
https://mdx-deck.jxnblk.com
MIT License
11.32k stars 605 forks source link

Is there a way to run custom javascript on deck load and slid transitions ? #772

Closed tjtaill closed 3 years ago

tjtaill commented 3 years ago

Hi sorry for a basic questions I want to give a talk/demo about snowplow analytics https://docs.snowplowanalytics.com/docs/getting-started-on-snowplow-open-source/what-is-snowplow-open-source/ and it would be neat if I could embed the snowplow javascript tracker https://docs.snowplowanalytics.com/docs/collecting-data/collecting-from-own-applications/javascript-tracker/ in the presentation itself so it tracks the page views of the presentation. I read something about custom mdx provider but maybe there is an easier way with callbacks or react hooks ?

Anyways any pointers you could provider would be greatly appreciated.

ChristianMurphy commented 3 years ago

mdx-deck provides a useDeck hook which can be used to observe the slide show state and could likely be used to call a function on state/slide/step change.

tjtaill commented 3 years ago

I notice there isn't to any docs or examples on how to use useDeck. Even reading the source code is not very insightful but still it is more than I had before thanks

tjtaill commented 3 years ago

In the end I wound up doing this

{pageView()}
where pageView wrapped the other function to return null, undefined or something renderable it works