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

discus-lib

v1.3.1

Published

A user discussion component library where the user can comment on a post and discuss among other users.

Downloads

27

Readme

discus-lib

A user discussion component library where the user can comment on a post and discuss among other users.

Overview

discus-lib is a React component library built using TypeScript. It provides Comment box where users can post comments and a Comment to display all the posted comments.

Installation

You can install discus-lib via npm:

npm i discus-lib

Usage

To use discus-lib, import the Discus component and integrate it into your React application. Ensure to remove <React.StrictMode> tags when using this component to prevent multiple renders.

The component can also take two properties:

  • name: "string" that holds the name of the user to be displayed. If the property is not mentioned it will display as Unknown User
  • discussion: "CommentType[]" that hold the initial value for the package.
  • setDiscussion: "React state function" that hold the function to set the comments from the package and that can be manipulated in the actual component.
import React, { useState } from 'react';
import { Discus } from 'discus-lib';

// TypeScript types

type CommentType = {
  id: string;
  userName: string;
  comment: string;
  timestamp: Date;
  reply: CommentType[];
  likeCount: number;
  dislikeCount: number;
  parentId: string;
};

type DiscusProps = {
  name: string;
  discussion: CommentType[];
  setDiscussion: React.Dispatch<React.SetStateAction<CommentType[] | undefined>>;
};

// App Component

const App: React.FC = () => {
  const [discussion, setDiscussion] = useState<CommentType[] | undefined>(discussion);

  const discusProps: DiscusProps = {
    name: "Person 1",
    discussion
    setDiscussion,
  };

  return (
    <div className="App">
      <h1>My App</h1>
      <Discus {...discusProps} />
    </div>
  );
};

export default App;

The width of the component can be modified by the width of the outer div in which it is wrapped.

Output

The comments schema which is captured in the setDiscussion state function will be as an array[] of object that is shown as below.

CommentType = [
  {
    id: string;
    userName: string;
    comment: string;
    timestamp: Date;
    reply: [
        {
        id: string;
        userName: string;
        comment: string,
        timestamp: Date;
        reply: CommentType[];
        likeCount: number;
        dislikeCount: number;
        parentId: string;
      },
    ],
    likeCount: number;
    dislikeCount: number;
    parentId: string;
  },
]

Note

Discus component is a recursion based component where the Comment component will recursively call the CommentBox component for replying on that comment.

License

This project is licensed under the MIT License. See the LICENSE file for details.