npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-discord-widget

v1.1.3

Published

Discord widget as React components

Downloads

124

Readme

React Discord Widget

Version License

Overview

react-discord-widget is a React component library designed to seamlessly integrate Discord server information into your web application. Display the online member count, server channels, and a quick join button with ease, while also offering a customizable interface for a more personal touch.

Features

  • Display real-time server data: online members, channels, etc.
  • Customizable styles to match your app's theme
  • Light and Dark theme support
  • Configurable via simple props
  • TypeScript support for strong typing

Example of usage

Quick Links

Installation

npm install react-discord-widget
yarn add react-discord-widget

Usage

Basic Example

import React from 'react';
import { Discord } from 'react-discord-widget';

function App() {
  return (
    <div>
      <h1>My Awesome Discord Server</h1>
      <Discord serverId="YOUR_SERVER_ID" />
    </div>
  );
}

export default App;

Advanced Configuration

<Discord
  serverId="YOUR_SERVER_ID"
  width={300}
  height={400}
  theme="dark"
  showMembers={true}
  showOnline={true}
  showJoinButton={true}
/>

Generate your own style

The useDiscord hook provides an easy way to integrate Discord server information into your React application. It automatically fetches data from your Discord server and provides it, along with several utility states and functions, to your component.

Parameters

  • id: The Discord server ID for which you want to fetch information.
  • delay: Optional. The number of seconds to wait before re-fetching the data. Defaults to 120 seconds if not specified.

Return Values

The hook returns an object containing:

  • isLoading: A boolean that indicates if the data is currently being loaded.
  • error: An error object if the request failed, or null if there's no error.
  • data: The server data retrieved from Discord's API, or null if the data is not available yet.
  • refetch: A function to manually re-fetch the data from the server.
  • remove: A function that resets the data and error states and sets isLoading to true.
  • delay: The actual delay that is used for the automatic refetch, in seconds.

Usage Example

const discordInfo = useDiscord({
  id: 'YOUR_SERVER_ID',
  delay: 120
});

Here's how you would typically use useDiscord within a functional component:

import React from 'react';
import { useDiscord } from 'react-discord-widget';

function DiscordComponent() {
  const { isLoading, data, error, refetch } = useDiscord({
    id: 'YOUR_SERVER_ID'
  });

  if (isLoading) {
    return <div>Loading...</div>;
  }

  if (error) {
    return <div>Error: {error.toString()}</div>;
  }

  return (
    <div>
      <h1>Discord Server Info</h1>
      {data && (
        <div>
          <p>Server Name: {data.name}</p>
          <button onClick={refetch}>Refresh</button>
        </div>
      )}
    </div>
  );
}

License

This project is licensed under the MIT License. Feel free to use and modify it as you see fit.

Contributing

Please report any issues or suggestions on the repository's issue tracker.

Feel free to use and enjoy the react-discord-widget component in your web applications! If you have any questions or need assistance, don't hesitate to reach out or open an issue on the GitHub repository.