Skip to content

Commit 04e3653

Browse files
committed
minor bug fix; added codesandbox example
1 parent fde7daf commit 04e3653

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This is a wrapper component for your scrollable component. Wrap your component w
2424
| triggerPoint | 'center', 'top', 'bottom | false | Trigger point for DetectSection (default: center) |
2525
| index | number | false | This spectifies which section(index) the needs to be scrolled to the viewport. Default value: 0 (note: this is an experimental feature) |
2626

27+
[Codesandbox demo](https://codesandbox.io/s/inspiring-goldwasser-5k13y?fontsize=14&hidenavigation=1&theme=dark)
2728

2829
#### Example
2930
```typescript

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-scroll-detect",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "Scroll detect component",
55
"main": "dist/index.js",
66
"module": "dist/index.es.js",

src/lib/ReactScrollDetect.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ const _ScrollContainer: FC = (props) => {
4444

4545

4646
useEffect(() => {
47+
if (index !== currentIndex) {
48+
setCurrentIndex(index)
49+
onChange(index)
50+
}
4751
window.scrollTo({ top: sectionEntryPoints[index] || 0, behavior: 'smooth' })
4852
}, [index])
4953

0 commit comments

Comments
 (0)