Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
react-scrollable-feed
Advanced tools
react-scrollable-feed Smart scrolling for chat UIs and feeds <img al
UX-wise, asking a user to scroll down manually a chat box when new messages arrive is quite painful. react-scrollable-feed aims to alleviate the burden of managing scrolling concerns from React developers. The same concept applies to any other kind of feed where new content arrives dynamically.
View a live demo here.
npm install --save react-scrollable-feed
import * as React from 'react'
import ScrollableFeed from 'react-scrollable-feed'
class App extends React.Component {
render() {
const items = ['Item 1', 'Item 2'];
return (
<ScrollableFeed>
{items.map((item, i) => <div key={i}>{item}</div>)}
</ScrollableFeed>
);
}
}
boolean
false
If set to true, will scroll to the bottom after each update on the component. By default, if the scrollable section is not at the bottom before the update occurs, it will leave the scroll at the same position.
(element: HTMLElement, offset: number) => void
if (element.scrollBy) {
element.scrollBy({ top: offset });
}
else {
element.scrollTop = offset;
}
Allows to override the scroll animation by any implementation.
() => void
() => {}
Is called after the scroll animation has been executed.
(previousProps: ScrollableFeedComponentProps, newProps: ScrollableFeedComponentProps) => boolean
() => true
Allows to customize when the scroll should occur. This will be called everytime a componentDidUpdate
happens, which means everytime one of the props changes. You will receive as parameters the previous and the new props.
Note: ScrollableFeedComponentProps
is defined as React.PropsWithChildren<ScrollableFeedProps>
If you want to compare the last children from both the previous and new props, you could do something like this :
import * as React from 'react'
import ScrollableFeed from 'react-scrollable-feed'
class App extends React.Component {
changeDetectionFilter(previousProps, newProps) {
const prevChildren = previousProps.children;
const newChildren = newProps.children;
return prevChildren !== newChildren
&& prevChildren[prevChildren.length - 1] !== newChildren[newChildren.length - 1];
}
render() {
const items = ['Item 1', 'Item 2'];
return (
<ScrollableFeed
changeDetectionFilter={this.changeDetectionFilter}
>
{items.map((item, i) => <div key={i}>{item}</div>)}
</ScrollableFeed>
);
}
}
export default App;
string
undefined
CSS
class that can be added on the wrapping div created by ScrollableFeed
.
number
2
Indicates the number of pixels of difference between the actual bottom and the current position that can be tolerated. The default setting should be fine for most use cases.
(isAtBottom: boolean) => void
() => {}
Is called when the onScroll
event is triggered on the wrapper div created by ScrollableFeed
.
Provides isAtBottom
boolean value as a parameter, which indicates if the scroll is at bottom position, taking viewableDetectionEpsilon
into account.
() => void
Scroll to the bottom
For more details on how to integrate react-scrollable-feed in your application, have a look at the example folder.
BSD 3-Clause © Gabriel Bourgault
See license.
2.0.0 (2023-12-31)
<a name="1.3.2"></a>
FAQs
react-scrollable-feed Smart scrolling for chat UIs and feeds <img al
The npm package react-scrollable-feed receives a total of 9,032 weekly downloads. As such, react-scrollable-feed popularity was classified as popular.
We found that react-scrollable-feed demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.