From a723b97df5cb22a401786eea58675d6612fb6860 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Wed, 5 Oct 2022 14:46:37 +0800 Subject: [PATCH] doc: Update `react.md` cheatsheet. --- docs/quickreference.md | 29 +++++++++++++++++++++++++++++ docs/react.md | 28 ++++++++++++++-------------- package.json | 2 +- scripts/create.mjs | 1 + scripts/style.css | 13 +++++++++++++ 5 files changed, 58 insertions(+), 15 deletions(-) diff --git a/docs/quickreference.md b/docs/quickreference.md index 528fcf7..0c6643e 100644 --- a/docs/quickreference.md +++ b/docs/quickreference.md @@ -124,6 +124,24 @@ function () {} 注释配置添加 `show-header` 类,放置在表格下面,表头将被展示出来。 +### 代码行高亮 + + +```jsx {1,4-5} +import React from "react"; +import "./Student.css"; + +export const Student = ( +
+); +``` + +上面 `{1,4-5}` 行代码高亮,下面是 `Markdown` 代码示例 + +```markdown + ```jsx {1,4-5} +``` + ### Tooltips [鼠标移动到上面有提示](https://github.com/jaywcjlove/reference) _Tooltips 的提示内容_ @@ -147,6 +165,8 @@ function () {} ``` +在 H3 标题下面添加样式标注 `` + ### 快捷键样式 | Key | value | @@ -157,6 +177,15 @@ function () {} 列表添加 `` 样式类,展示快捷键样式。 +### 代码行号 + +```jsx showLineNumbers +export const Student = ( + +); +``` + + ### 内置类样式 :- | - diff --git a/docs/react.md b/docs/react.md index 7f2e309..cce3fdd 100644 --- a/docs/react.md +++ b/docs/react.md @@ -61,7 +61,7 @@ const Example =您点击了 {count} 次
@@ -197,13 +195,15 @@ function Student() { #### Class 中的 State -```jsx +```jsx {6,12,20} import React from 'react'; class Student extends React.Component { constructor(props) { super(props); this.state = {count: 1}; + // 确保函数可以访问组件属性(ES2015) + this.click = this.click.bind(this); } click() { const count = this.state.count; @@ -312,7 +312,7 @@ render() { ### Fragment -```jsx +```jsx {1,6,9} import { Fragment } from 'react' import Avatar from './Avatar'; import Profile from './Profile'; @@ -384,7 +384,7 @@ const ref = React.createRef(); ### Class 组件内部使用 ref 属性 -```jsx +```jsx {6,10} import {Component,createRef} from 'react' class MyComponent extends Component { @@ -403,7 +403,7 @@ class MyComponent extends Component { ### 函数组件内部使用 ref 属性 -```jsx +```jsx {3,9} function CustomTextInput(props) { // 这里必须声明 $input,这样 ref 才可以引用它 const $input = useRef(null); @@ -424,7 +424,7 @@ function CustomTextInput(props) { ### 严格模式 StrictMode -```jsx +```jsx {3,8}