Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/skn437/skn-react-types

A Simple Type Definition Extension Library For React.js 18
https://github.com/skn437/skn-react-types

bun library nextjs nodejs react types typescript

Last synced: about 1 month ago
JSON representation

A Simple Type Definition Extension Library For React.js 18

Awesome Lists containing this project

README

        

# SKN React Type Extension Library

react

> TypeScript React

[![NPM Version](https://img.shields.io/npm/v/%40best-skn%2Freact-types)](https://www.npmjs.com/package/@best-skn/react-types) [![MIT License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/license/mit)

ย 

## **_Introduction:_**

### This is a simple TypeScript Type Extension Library for React 18 & also for Next.js 14

### I made this library so that I can use it in all of my Next.js 14 projects without writing the same codes over and over again

ย 

## **_Details:_**

### **`SC/SFC` Type**

- type `SC/SFC` both are for server components except for layout ones (layout.tsx in Next.js 14)
- type `SC/SFC` both take generic type of any kinds of props
- `SC` is used in asynchronous server components that returns a `Promise` of `React.JSX.Element | React.ReactNode`
- `SFC` is used in synchronous server components that returns `React.JSX.Element | React.ReactNode`
- For usage instruction, see `Usage` section

### **`ChildrenProps` Type**

- An interface that has `children` property of type `React.JSX.Element | React.ReactNode`
- For usage instruction, see `Usage` section

### **`SLC/SFLC` Type**

- type `SLC/LSFC` both are for layout server components (layout.tsx in Next.js 14)
- type `SLC/SFLC` don't take any generics
- `SLC` is used in asynchronous layout server components that returns a `Promise`
of `React.JSX.Element | React.ReactNode`
- `SFLC` is used in synchronous layout server components that returns `React.JSX.Element | React.ReactNode`
- For usage instruction, see `Usage` section

ย 

## **_Use Case:_**

- React
- Next.js

ย 

## **_Requirements:_**

### This library has peer dependency for React & React DOM of minimum 18.3.1. It may or may not work on 19.x

### This library is intended to be used in Next.js of minimum 14.2.3. It may or may not work on 15.x

- ๐Ÿ’€ Minimum [react](https://www.npmjs.com/package/react) Version: `18.3.1`
- ๐Ÿ’€ Minimum [@types/react](https://www.npmjs.com/package/@types/react) Version: `18.3.3`
- ๐Ÿ’€ Minimum [react-dom](https://www.npmjs.com/package/react-dom) Version: `18.3.1`
- ๐Ÿ’€ Minimum [@types/react-dom](https://www.npmjs.com/package/@types/react-dom) Version: `18.3.0`
- ๐Ÿ’€ Minimum [next](https://www.npmjs.com/package/next) Version: `14.2.3`

ย 

## **_Complementary Libraries:_**

- [@best-skn/next-types](https://www.npmjs.com/package/@best-skn/next-types)

ย 

## **_Usage:_**

### To install the package, type the following in console

> ```zsh
> npm add -D @best-skn/react-types
> #or
> yarn add -D @best-skn/react-types
> #or
> pnpm add -D @best-skn/react-types
> #or
> bun add -D @best-skn/react-types
> ```

### Create a directory called `types` in the root location of your project, and create a file called `react.d.ts`, then do this

> ```typescript
> import "@best-skn/react-types";
> ```

### Check your `tsconfig.json` if `includes` property has `**/*.ts` or not otherwise the type definition file may not work

### Now Inside your Next.js 14 Project, use the package like this (Just an example)

#### **_`SC/SFC` Type:_**

#### For any `Server Components` except the `Layout Server Components`, do the following

> ##### **(a) Asynchronous:**
>
> ```typescript jsx
> // Location: app/page.tsx
> const Home: React.SC = async () => {
> return (
>

something...

> );
> };
>
> export default Home;
> ```
>
> ##### **(b) Synchronous:**
>
> ```typescript jsx
> // Location: app/page.tsx
> const Home: React.SFC = () => {
> return (
>
something...

> );
> };
>
> export default Home;
> ```

#### **_`ChildrenProps` Type:_**

#### For any kinds of `Functional Component (Server or Client)`, you can use like this if it needs `children` props

> ##### **(a) Server:**
>
> ```typescript jsx
> import type { ChildrenProps } from "react";
>
> const HomeComponent: React.SFC = (props) => {
> const { children } = props;
>
> return (
>

something...

> );
> };
>
> export default HomeComponent;
> ```
>
> ##### **(b) Client:**
>
> ```typescript jsx
> "use client"
>
> import type { ChildrenProps } from "react";
>
> const HomeComponent: React.FC = (props) => {
> const { children } = props;
>
> return (
>
something...

> );
> };
>
> export default HomeComponent;
> ```

#### **_`SLC/SFLC` Type:_**

#### For any `Layout Server Components`, do the following

> ##### **(a) Asynchronous case:**
>
> ```typescript jsx
> // Location: app/layout.tsx
> const RootLayout: React.SLC = async (props) => {
> const { children } = props;
>
> return (
>
> {children}
>
> );
> };
>
> export default RootLayout;
> ```
>
> ##### **(a) Synchronous case:**
>
> ```typescript jsx
> // Location: app/layout.tsx
> const RootLayout: React.SFLC = (props) => {
> const { children } = props;
>
> return (
>
> {children}
>
> );
> };
>
> export default RootLayout;
> ```

ย 

## **_Dedicated To:_**

- ๐Ÿ‘ฉโ€โš•๏ธ`Tanjila Hasan Trina`: The long lost love of my life. The course of nature separated us from our paths and put us in separate places far away from each other. But no matter how separated we are right now, each and every moment of mine is only dedicated to you. We may not see each other in this lifetime as it seems but I will find you again in the next life. I just want to say: `ไธ–็•Œใฏๆฎ‹้…ทใ  ใใ‚Œใงใ‚‚ๅ›ใ‚’ๆ„›ใ™ใ‚ˆ`
- ๐Ÿ’ฏ`My Parents`: The greatest treasures of my life ever.

ย 

## **_License:_**

Copyright (C) 2024 SKN Shukhan

Licensed under the MIT License