Skip to content

Instantly share code, notes, and snippets.

View MR-Mostafa's full-sized avatar
🎯
Focusing

Mostafa Rahmati MR-Mostafa

🎯
Focusing
View GitHub Profile
@MR-Mostafa
MR-Mostafa / polymorphic-components-react-8.tsx
Created November 22, 2023 20:56
Build strongly typed polymorphic components with React and TypeScript - Part 8
import * as React from 'react';
type Rainbow = "red" | "orange" | "yellow" | "green" | "blue" | "indigo" | "violet";
type ButtonProps<C extends React.ElementType> = {
as?: C;
color?: Rainbow | "black";
};
type Props <C extends React.ElementType> =
@MR-Mostafa
MR-Mostafa / polymorphic-components-react-7.tsx
Created November 22, 2023 20:46
Build strongly typed polymorphic components with React and TypeScript - Part 7
/**
* قبل از تغییر
*/
type Props <C extends React.ElementType> = React.PropsWithChildren<ButtonProps<C>> & React.ComponentPropsWithoutRef<C>;
/**
* بعد از تغییر
*/
type Props <C extends React.ElementType> =
React.PropsWithChildren<ButtonProps<C>> &
@MR-Mostafa
MR-Mostafa / polymorphic-components-react-6.tsx
Last active November 22, 2023 20:34
Build strongly typed polymorphic components with React and TypeScript - Part 6
import * as React from 'react';
type Rainbow = "red" | "orange" | "yellow" | "green" | "blue" | "indigo" | "violet";
/**
* از تایپ پایین، این دو مورد حذف شدند:
* children: React.ReactNode
* React.ComponentPropsWithoutRef<C>
*/
@MR-Mostafa
MR-Mostafa / polymorphic-components-react-5.tsx
Last active November 22, 2023 20:30
Build strongly typed polymorphic components with React and TypeScript - Part 5
import * as React from 'react';
type Rainbow = "red" | "orange" | "yellow" | "green" | "blue" | "indigo" | "violet";
type ButtonProps<C extends React.ElementType> = {
as?: C;
color?: Rainbow | "black"; // 👈 look here
children: React.ReactNode;
} & React.ComponentPropsWithoutRef<C>;
@MR-Mostafa
MR-Mostafa / polymorphic-components-react-4.tsx
Last active November 22, 2023 20:30
Build strongly typed polymorphic components with React and TypeScript - Part 4
import * as React from 'react';
type ButtonProps<C extends React.ElementType> = {
as?: C;
children: React.ReactNode;
} & React.ComponentPropsWithoutRef<C>;
// 👇 look here
export const Button = <C extends React.ElementType = 'button'>({
as,
@MR-Mostafa
MR-Mostafa / polymorphic-components-react-3.tsx
Last active November 22, 2023 20:30
Build strongly typed polymorphic components with React and TypeScript - Part 3 (Support Other Valid Props, Based On The Value Of As)
import * as React from 'react';
type ButtonProps<C extends React.ElementType> = {
as?: C;
children: React.ReactNode;
} & React.ComponentPropsWithoutRef<C>; // 👈 look here
export const Button = <C extends React.ElementType>({
as,
children,
@MR-Mostafa
MR-Mostafa / polymorphic-components-react-2.tsx
Last active November 22, 2023 20:29
Build strongly typed polymorphic components with React and TypeScript - Part 2
import * as React from 'react';
/**
* یک جنریک تایپ است که بیانگر React.ElementType تایپ
* 1. می‌باشد HTML تمامی تگ‌های ولید و معتبر
* 2. می‌تواند یک کامپوننت ری‌اکتی باشد
*/
type ButtonProps<C extends React.ElementType> = {
as?: C;
children: React.ReactNode;
@MR-Mostafa
MR-Mostafa / polymorphic-components-react-1.tsx
Last active November 22, 2023 19:44
Build strongly typed polymorphic components with React and TypeScript - Part 1
import * as React from 'react';
const Button = ({as, children, ...otherProps}) => {
/*
* نمی‌توانیم به عنوان یک کامپوننت به صورت زیر استفاده کنیم as توجه داشته باشید که ما از پراپس
* <as> ... </as>
* به این دلیل که در ری‌اکت حتما نیاز هست که نام کامپوننت با حرف بزرگ شروع شود
* @see https://t.ly/peF5w
*/
@MR-Mostafa
MR-Mostafa / gist:4d69b1b009b05c7a2405e4e0abf8a777
Last active October 27, 2020 21:45
Use fastest validator as a middleware in expressjs
// loginValidator.js
exports.loginValidator = {
email: {
type: 'email',
mode: 'precise',
normalize: 'true',
},
password: {
type: 'string',
convert: true,
@MR-Mostafa
MR-Mostafa / gist:907bf1e77dcfd839b103da573846a0f7
Created October 13, 2019 19:39 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue: