Skip to content

Commit 996938c

Browse files
Added github gist and codesandbox to useToggle, changed minor types in useDebounce, useHover, useOnScreen hooks
1 parent 6815560 commit 996938c

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

src/pages/useDebounce.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function useDebounce(value, delay) {
107107
}
108108
```
109109

110-
```typescript jsx
110+
```typescript
111111
import { useState, useEffect, useRef } from "react";
112112

113113
// Usage

src/pages/useHover.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function App() {
6464
// Hook
6565
// T - could be any type of HTML element like: HTMLDivElement, HTMLParagraphElement and etc.
6666
// hook returns tuple(array) with type [any, boolean]
67-
function useHover<T>(): [any, boolean] {
67+
function useHover<T>(): [MutableRefObject<T>, boolean] {
6868
const [value, setValue] = useState<boolean>(false);
6969

7070
const ref: any = useRef<T | null>(null);

src/pages/useOnScreen.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function useOnScreen(ref, rootMargin = "0px") {
8181
```
8282
8383
```typescript
84-
import { useState, useEffect, useRef } from "react";
84+
import { useState, useEffect, useRef, MutableRefObject } from "react";
8585
8686
// Usage
8787
function App() {
@@ -90,7 +90,7 @@ function App() {
9090
// Call the hook passing in ref and root margin
9191
// In this case it would only be considered onScreen if more ...
9292
// ... than 300px of element is visible.
93-
const onScreen: boolean = useOnScreen(ref, "-300px");
93+
const onScreen: boolean = useOnScreen<HTMLDivElement>(ref, "-300px");
9494
9595
return (
9696
<div>
@@ -118,7 +118,7 @@ function App() {
118118
}
119119

120120
// Hook
121-
function useOnScreen(ref: any, rootMargin: string = "0px"): boolean {
121+
function useOnScreen<T extends Element>(ref: MutableRefObject<T>, rootMargin: string = "0px"): boolean {
122122
// State and setter for storing whether element is visible
123123
const [isIntersecting, setIntersecting] = useState<boolean>(false);
124124

src/pages/useToggle.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
templateKey: post
33
title: useToggle
44
date: "2020-12-02"
5-
gist:
6-
sandbox:
5+
gist: https://gist.github.com/nikasepiskveradze/9db51bc37e1c87974528b7bc47b5268c
6+
sandbox: https://codesandbox.io/s/recursing-cori-ckw8p
77
isMultilingual: true
88
---
99

0 commit comments

Comments
 (0)