diff --git a/README.md b/README.md index 8b532bc..7417796 100644 --- a/README.md +++ b/README.md @@ -376,7 +376,7 @@ Quick Reference [winnerzr01.github.io](https://winnerzr01.github.io/Quick-Reference/index.html) [ref.isteed.cc](https://ref.isteed.cc/) [quickref.hestudio.xyz](https://quickref.hestudio.xyz) - + 如果你有资源,可以很方便部署 web 版,这非常简单,只需要克隆 [gh-pages](https://github.com/jaywcjlove/reference/tree/gh-pages) 分支代码到你的静态服务就可以了,还可以使用 [docker](https://hub.docker.com/r/wcjiang/reference) 快捷部署 web 版。 diff --git a/docs/react.md b/docs/react.md index e6fdd89..968a482 100644 --- a/docs/react.md +++ b/docs/react.md @@ -18,6 +18,7 @@ React 是一个用于构建用户界面的 JavaScript 库 - [React 官方文档](https://reactjs.org/) _(reactjs.org)_ - [Styled Components 备忘清单](./styled-components.md) _(jaywcjlove.github.io)_ +- [TypeScript JSX 备忘清单](./typescript.md#jsx) _(jaywcjlove.github.io)_ ```js import {createRoot} from 'react-dom/client' diff --git a/docs/typescript.md b/docs/typescript.md index 6759b2b..1832598 100644 --- a/docs/typescript.md +++ b/docs/typescript.md @@ -1,6 +1,11 @@ TypeScript 备忘清单 === +[![NPM version](https://img.shields.io/npm/v/typescript.svg?style=flat)](https://www.npmjs.com/package/typescript) +[![Downloads](https://img.shields.io/npm/dm/typescript.svg?style=flat)](https://www.npmjs.com/package/typescript) +[![Repo Dependents](https://badgen.net/github/dependents-repo/Microsoft/TypeScript)](https://github.com/Microsoft/TypeScript/network/dependents) +[![Github repo](https://badgen.net/badge/icon/Github?icon=github&label)](https://github.com/Microsoft/TypeScript) + 包含最重要基础、泛型、方法、class 等 TypeScript 强类型编程语言语法的快速参考备忘单。初学者的完整快速参考。 入门 Interface @@ -1265,6 +1270,24 @@ class Select extends React.Component, any> {} const Form = () => items={['a', 'b']} />; ``` +### 函数组件 ref + + +```tsx +import { FC, ForwardedRef, forwardRef, PropsWithRef } from "react"; + +function InternalProgress(props: ProgressProps, ref?: ForwardedRef) { + return ( +
+ {props.children} +
+ ) +} + +export interface ProgressProps extends React.DetailedHTMLProps, HTMLDivElement> {} +export const Progress: FC> = forwardRef(InternalProgress) +``` + 各种各样的技巧 --- @@ -1331,16 +1354,21 @@ const point = [3, 4] as const ```ts type Colors = 'red' | 'green' | 'blue'; +type RGB = [ + red: number, + green: number, + blue: number +]; +type Palette = Record -type RGB = [red: number, green: number, blue: number]; - -const palette: Record = { +const palette: Palette = { red: [255, 0, 0], green: '#00ff00', blue: [0, 0, 255], }; -// 通常的方式会推导出 redComponent 为 string | number | undefined +// 通常的方式会推导出 redComponent 为 +// => string | number | undefined const redComponent = palette.red.at(0); ```