nytimes / react-tracking

🎯 Declarative tracking for React apps.
https://open.nytimes.com/introducing-react-tracking-declarative-tracking-for-react-apps-2c76706bb79a
Other
1.88k stars 123 forks source link

Refactor into a render prop <Tracking render/> #50

Open jaredpalmer opened 7 years ago

tizmagik commented 7 years ago

Hey @jaredpalmer would be happy to accept a PR to support the render prop pattern, however the existing HoC pattern would still need to be supported.

eliseumds commented 6 years ago

@jaredpalmer what kind of API do you have in mind? I've been discussing with workmates the following:

<Tracking
  action="click"
  label={event => event.currentTarget.textContent}
  onClick={() => console.log('Some custom optional callback')}
>
  {trackingProps => (
    <Button btnStyle="facebook" {...trackingProps}>
      Like us on Facebook!
    </Button>
  )}
</Tracking>

The trackingProps object would have the onClick callback, in this case, but it could be anything: onExpand, onClose, etc. Does it make sense?

jaredpalmer commented 6 years ago

What about tracking on mount?

eliseumds commented 6 years ago

The Tracking component takes care of it. It could also inject listeners into the document (scroll, online, deviceorientation), for ex.

jaredpalmer commented 6 years ago

This gets hard to type with flow/ts if you couple the naming of the handler to the event

eliseumds commented 6 years ago

It doesn't necessarily need to be named onClick. It could be callback, for ex.