1.0.14 • Published 1 year ago

@logshq.io/react v1.0.14

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Official LogsHQ.io logger for React

The official LogsHQ.io notifier for capturing errors in React and reporting them to LogsHQ.

Installation

Using npm:

npm install @logshq.io/react

Using yarn:

yarn add @logshq.io/react

Usage

Create a Stream in the Dashboard, get your Stream and Project API KEYS, and use it like this:

// myLogger.js
const LogshqLogger = require('@logshq.io/react');

const logger = new LogshqLogger({
  project_id: 'SOME-PROJECT-ID',
  api_key: 'SOME-STREAM-KEY',
  environment: 'production', // optional
  hostname: 'auth-service', // optional
});

module.exports = logger

PS: This can work inside or outside of your Components, like Saga for example!.

Inside React Components

import React, { useState, useEffect } from 'react';
// Import the logger
import LogshqLogger from'@logshq.io/react';
import axios from 'axios';

// This could in a seperate module so it can be called inside Redux Saga or inside // any other component
const logger = new LogshqLogger({
  project_id: 'SOME-PROJECT-ID',
  api_key: 'SOME-STREAM-KEY',
  environment: process.env.NODE_ENV, // optional
  hostname: 'auth-service', // optional
});

const MyComponent = () =>{ 
  const [data, setData] = useState([]);
  
  const fetchData = async () => {
    try {
      // Calling your API endpoind
      const result = await axios(
        'https://some-domain.com/api/v1/search?query=myQuery',
      );
      // Success
      setData(result.data)
    } catch (error) {
      // Send the error and some additional details to help debugging properly
      logger.error(error, {
        component: 'MyComponent',
        someData: {
          someNestedData: 'Some Value'
        }
      })
    }
  };

  useEffect(() => {
    fetchData();
  }, []);

  return (
    <div>
      <ul>
        {
          data.map(item => (
            <li key={item.id}>
              <a href={item.url}>{item.title}</a>
            </li>
          ))
        }
      </ul>
    </div>
  );
}

export default MyComponent;

Catch JavaScript errors anywhere in your child components

See Error Boundaries

More docs

here

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago