@best-skn/react-types
v1.1.3
Published
A Simple Type Definition Extension Library For React.js 18
Readme
SKN React Type Extension Library
TypeScript React
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/SFCboth are for server components except for layout ones (layout.tsx in Next.js 14) - type
SC/SFCboth take generic type of any kinds of props SCis used in asynchronous server components that returns aPromiseofReact.JSX.Element | React.ReactNodeSFCis used in synchronous server components that returnsReact.JSX.Element | React.ReactNode- For usage instruction, see
Usagesection
ChildrenProps Type
- An interface that has
childrenproperty of typeReact.JSX.Element | React.ReactNode - For usage instruction, see
Usagesection
SLC/SFLC Type
- type
SLC/LSFCboth are for layout server components (layout.tsx in Next.js 14) - type
SLC/SFLCdon't take any generics SLCis used in asynchronous layout server components that returns aPromiseofReact.JSX.Element | React.ReactNodeSFLCis used in synchronous layout server components that returnsReact.JSX.Element | React.ReactNode- For usage instruction, see
Usagesection
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 Version:
18.3.1 - 💀 Minimum @types/react Version:
18.3.3 - 💀 Minimum react-dom Version:
18.3.1 - 💀 Minimum @types/react-dom Version:
18.3.0 - 💀 Minimum next Version:
14.2.3
Complementary Libraries:
Usage:
To install the package, type the following in console
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
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:
// Location: app/page.tsx const Home: React.SC<unknown> = async () => { return ( <div>something...</div> ); }; export default Home;(b) Synchronous:
// Location: app/page.tsx const Home: React.SFC<unknown> = () => { return ( <div>something...</div> ); }; 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:
import type { ChildrenProps } from "react"; const HomeComponent: React.SFC<ChildrenProps> = (props) => { const { children } = props; return ( <div>something...</div> ); }; export default HomeComponent;(b) Client:
"use client" import type { ChildrenProps } from "react"; const HomeComponent: React.FC<ChildrenProps> = (props) => { const { children } = props; return ( <div>something...</div> ); }; export default HomeComponent;
SLC/SFLC Type:
For any Layout Server Components, do the following
(a) Asynchronous case:
// Location: app/layout.tsx const RootLayout: React.SLC = async (props) => { const { children } = props; return ( <html lang="en"> <body>{children}</body> </html> ); }; export default RootLayout;(a) Synchronous case:
// Location: app/layout.tsx const RootLayout: React.SFLC = (props) => { const { children } = props; return ( <html lang="en"> <body>{children}</body> </html> ); }; export default RootLayout;
Dedicated To:
- 👩🎨
Prodipta Das Logno& 🧛♀️Atoshi Sarker Prithula: The two most special ladies of my life. My best wishes will always be with you two. May you two always be happy. - 💯
My Parents: The greatest treasures of my life ever.
License:
Copyright (C) 2024 SKN Shukhan
Licensed under the MIT License
