Skip to content

Commit 6e00cf5

Browse files
committed
docs: simplify ref usage example
1 parent b30a098 commit 6e00cf5

2 files changed

Lines changed: 18 additions & 24 deletions

File tree

README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,15 @@ Then open `http://localhost:8000`.
106106
### Refs
107107

108108
```tsx | pure
109-
import React from 'react';
110-
import Input, {
111-
TextArea,
112-
type InputRef,
113-
type TextAreaRef,
114-
} from '@rc-component/input';
115-
116-
const inputRef = React.useRef<InputRef>(null);
117-
const textareaRef = React.useRef<TextAreaRef>(null);
118-
119-
inputRef.current?.focus();
120-
textareaRef.current?.blur();
109+
import type { InputRef, TextAreaRef } from '@rc-component/input';
110+
111+
function focusInput(inputRef: InputRef | null) {
112+
inputRef?.focus();
113+
}
114+
115+
function blurTextArea(textareaRef: TextAreaRef | null) {
116+
textareaRef?.blur();
117+
}
121118
```
122119

123120
| Ref | Methods |

README.zh-CN.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,15 @@ npm start
106106
### Refs
107107

108108
```tsx | pure
109-
import React from 'react';
110-
import Input, {
111-
TextArea,
112-
type InputRef,
113-
type TextAreaRef,
114-
} from '@rc-component/input';
115-
116-
const inputRef = React.useRef<InputRef>(null);
117-
const textareaRef = React.useRef<TextAreaRef>(null);
118-
119-
inputRef.current?.focus();
120-
textareaRef.current?.blur();
109+
import type { InputRef, TextAreaRef } from '@rc-component/input';
110+
111+
function focusInput(inputRef: InputRef | null) {
112+
inputRef?.focus();
113+
}
114+
115+
function blurTextArea(textareaRef: TextAreaRef | null) {
116+
textareaRef?.blur();
117+
}
121118
```
122119

123120
| Ref | 方法 |

0 commit comments

Comments
 (0)