1.3.1 • Published 10 months ago

discus-lib v1.3.1

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

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.

1.3.1

10 months ago

1.3.0

10 months ago

1.2.6

11 months ago

1.2.5

11 months ago

1.2.4

11 months ago

1.2.3

11 months ago

1.2.0

12 months ago

1.0.19

12 months ago

1.0.18

12 months ago

1.0.17

12 months ago

1.0.16

12 months ago

1.2.2

12 months ago

1.2.1

12 months ago

1.0.20

12 months ago

1.0.15

12 months ago

1.0.9

12 months ago

1.0.8

12 months ago

1.0.7

12 months ago

1.0.11

12 months ago

1.0.10

12 months ago

1.0.14

12 months ago

1.0.13

12 months ago

1.0.12

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago

0.10.0

12 months ago

0.9.0

12 months ago

0.8.0

12 months ago

0.7.0

12 months ago

0.6.0

12 months ago

0.5.0

12 months ago

0.4.0

12 months ago

0.3.0

12 months ago

0.2.0

12 months ago

0.1.0

12 months ago