1.0.2 • Published 12 months ago

logsnag-react v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Unofficial LogSnag React

Package status License

Getting started

Install

yarn add logsnag-react

Usage

LogSnag Provider

First, wrap your application with the LogSnagProvider at the top level of your application, similar to other context providers. The provider requires token and project props.

import React from 'react'
import { LogSnagProvider } from 'logsnag-react'

const App: React.FC = () => (
  <LogSnagProvider token="your_token" project="your_project">
    {/* Your app code here */}
  </LogSnagProvider>
)

useLogSnag Hook

The useLogSnag hook provides access to two functions: logEvent and logInsight.

import React from 'react'
import { useLogSnag } from 'logsnag-react'

const YourComponent: React.FC = () => {
  const { logEvent, logInsight } = useLogSnag()

  const yourFunction = async () => {
    await logEvent({
      channel: 'your_channel',
      event: 'your_event',
      description: 'your_description',
      icon: 'your_icon',
      tags: {
        key: 'your_value',
      },
      notify: true,
    })

    await logInsight({
      title: 'your_title',
      value: 'your_value',
      icon: 'your_icon',
    })
  }

  return (
    // Your component code here
  )
}

Notes

The useLogSnag hook must be used within a component that is a child of the LogSnagProvider component. If you attempt to use it outside of this context, an error will be thrown.

Official documentation

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago