You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 1, 2025. It is now read-only.
@@ -72,82 +73,14 @@ There are a lot of hash scrolling React libraries out there, so why should you p
72
73
- Most other libraries rely on scrolling by id, whereas this library relies on ref scrolling, making it more robust for large projects
73
74
- This library offers built-in [TypeScript](https://www.typescriptlang.org/) support
74
75
- Extensive testing makes this library more dependable
75
-
-The components that this library provides are very customizable, making it more likely that they will fit your use case
76
+
-This library provides components that are very customizable, making it more likely that they will fit your use case
76
77
77
78
---
78
79
79
-
## Usage
80
+
## Components
80
81
81
82
**Note**: [react-router-dom](https://reactrouter.com/web/) is required as a peer dependency and all components must be wrapped in a [Router](https://reactrouter.com/web/api/BrowserRouter)
82
83
83
-
### HashScroll
84
-
85
-
- In this example, the div with text "Element #1" will be scrolled to the center of the page when the url hash is "#hash1".
86
-
- The div with text "Element #2" will only be scrolled to when both the hash and the pathname are "#hash2" and "/docs", respectively.
87
-
88
-
```javascript
89
-
importReactfrom"react";
90
-
import { BrowserRouter } from"react-router-dom"; //Can use HashRouter or MemoryRouter as well
Hello! (This does not work! Neither does <>Hello!</>) Children must be elements!
176
+
</HashScroll>
177
+
</BrowserRouter>
178
+
);
179
+
};
180
+
181
+
constHashChild=React.forwardRef((props, ref)) => ( // Must forward refs for custom HashScroll children
182
+
<div ref={ref}>{props.children}</div>
183
+
)
184
+
```
185
+
186
+
---
249
187
250
188
### MultiHash
251
189
252
190
Component that pairs hashes with refs and scrolls to a corresponding ref when one of the hashes is present in the url
253
191
254
-
#### hashes
192
+
#### Props
193
+
194
+
`hashes`
255
195
256
196
-**Required**
257
-
- An object specifying the hashes and the refs they correspond to
197
+
- An object specifying the hashes and the refs or refs with options ([behavior](#behavior), [position](#position), [requiredPathname](#requiredpathname), [scrollFunc](#scrollfunc)) they correspond to
258
198
- Hashes can include or exclude leading "#"
259
-
- Each hash corresponds to a ref or a ref with options ([behavior](#behavior), [position](#position), [requiredPathname](#requiredpathname), [scrollFunc](#scrollfunc))
260
-
- Example:
261
-
262
-
```javascript
263
-
constref1=createRef();
264
-
constref2=createRef();
265
-
consthashes= {
266
-
hash1: ref1,
267
-
"#hash2": [
268
-
ref2,
269
-
{
270
-
behavior:"auto",
271
-
requiredPathname: ["/docs", "/contact"],
272
-
},
273
-
],
274
-
};
275
-
276
-
return<MultiHash hashes={hashes} />;
277
-
```
278
-
279
-
#### [behavior](#behavior)<!-- omit in toc -->
199
+
200
+
[`behavior`](#behavior)
280
201
281
202
- Applies to all hashes unless overriden by a ref with options
282
203
283
-
#### [position](#position)<!-- omit in toc -->
204
+
[`position`](#position)
284
205
285
206
- Applies to all hashes unless overriden by a ref with options
286
207
287
-
#### [requiredPathname](#requiredpathname)<!-- omit in toc -->
208
+
[`requiredPathname`](#requiredpathname)
288
209
289
210
- Applies to all hashes unless overriden by a ref with options
290
211
291
-
#### [scrollFunc](#scrollfunc)<!-- omit in toc -->
212
+
[`scrollFunc`](#scrollfunc)
292
213
293
214
- Applies to all hashes unless overriden by a ref with options
294
215
216
+
#### Example
217
+
218
+
```javascript
219
+
importReactfrom"react";
220
+
import { BrowserRouter } from"react-router-dom"; //Can use HashRouter or MemoryRouter as well
Scrolls to corresponding child element when one of the hashes is present in the url
254
+
255
+
#### Props
256
+
257
+
`hashes`
258
+
259
+
-**Required**
260
+
- Array of hashes or hashes with scroll options ([behavior](#behavior), [position](#position), [requiredPathname](#requiredpathname), [scrollFunc](#scrollfunc))
261
+
- Hashes can include or exclude leading "#"
262
+
- Length should be equal to children length
263
+
264
+
[`behavior`](#behavior)
265
+
266
+
[`position`](#position)
267
+
268
+
[`requiredPathname`](#requiredpathname)
269
+
270
+
[`scrollFunc`](#scrollfunc)
271
+
272
+
#### Example
273
+
274
+
```javascript
275
+
importReactfrom"react";
276
+
import { BrowserRouter } from"react-router-dom"; //Can use HashRouter or MemoryRouter as well
0 commit comments