Skip to content

Commit 1e0ee48

Browse files
authored
Update README.md
1 parent 3481b5b commit 1e0ee48

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,19 @@ A helper function that automatically types tuples can also be helpful if you wri
260260
```ts
261261
function tuplify<T extends any[]>(...elements: T) { return elements }
262262

263-
const myTuple = tuplify(false, 1, 'a') // type is [boolean, number, string]
263+
function useArray() {
264+
const numberValue = useRef(3).current
265+
const functionValue = useRef(() => {}).current
266+
return [numberValue, functionValue] // type is (number | (() => void))[]
267+
}
268+
269+
function useTuple() {
270+
const numberValue = useRef(3).current
271+
const functionValue = useRef(() => {}).current
272+
return tuplify(numberValue, functionValue) // type is [number, () => void]
273+
}
264274
```
275+
The React team recommends that custom hooks that return more than two values should use proper objects instead of tuples, however.
265276

266277
If you are writing a React Hooks library, don't forget that you should also expose your types for users to use.
267278

0 commit comments

Comments
 (0)