@logary/plugin-react
v6.0.0-beta.8
Published
A plugin for the popular React framework.
Downloads
2
Maintainers
Readme
Logary JS — React Plugin
A plugin for the popular React framework.
npm add @logary/plugin-react
Usage
For details, see ./examples/with-nextjs
in the repository.
In your logary.ts
:
import react from '@logary/plugin-react'
const logary = getLogary({ ... }) // configure targets and Logary Analytics ID here
react(logary)
// more plugins here
export default logary
You can now use the useLogary hook to get the Logary instance:
import '../lib/logary' // ensure Logary is instantiated (best placed in App.tsx)
// now you can use the hooks in your components:
import { useLogary, useLogger } from '@logary/plugin-react'
export default function Button({ onClick, children }) {
const { event } = useLogger('MyApp', 'Button')
function handleClick(e: Event) {
event('Made purchase', { amount: 20.3, currency: 'USD' })
onClick(e)
}
return (
<button onClick={handleClick}>
{children}
</button>
)
}