Research
Security News
Malicious PyPI Package ‘pycord-self’ Targets Discord Developers with Token Theft and Backdoor Exploit
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
@catamphetamine/found-scroll
Advanced tools
Scroll management for Found.
import { createBrowserRouter, createRender } from 'found';
import { ScrollManager } from 'found-scroll';
/* ... */
const render = createRender({ renderError });
const BrowserRouter = createBrowserRouter({
routeConfig,
render: (renderArgs) => (
<ScrollManager renderArgs={renderArgs}>{render(renderArgs)}</ScrollManager>
),
});
$ npm i -S react found
$ npm i -S found-scroll
When constructing a router, in the render
method, wrap the rendered element with <ScrollManager>
, and pass in renderArgs
as a prop, as in the above example.
Generally only the window
scroll position is restored for a location. For
cases where you also want to restore alternative scroll container there is useScrollContainer
import { useScrollContainer } from 'found-scroll';
function MyScrollView() {
const scrollRef = useScrollContainer('my-scroll-view');
return <div ref={scrollRef} />;
}
Scroll containers are identified with a 'scrollKey'. There should only be one element associated with a given key for any given location. Think of it as similar to React's key
prop, in that it provides a stable identity for an element across renders.
You can provide a custom shouldUpdateScroll
callback as a prop to <ScrollManager>
. This callback receives the previous and the current renderArgs
.
The callback can return:
x
and y
, such as [0, 100]
, to scroll to that positionid
or name
of an element, to scroll to that elementconst shouldUpdateScrollByPathname = (prevRenderArgs, { location }) =>
!prevRenderArgs || location.pathname !== prevRenderArgs.location.pathname;
const shouldUpdateScrollByRoute = (prevRenderArgs, { routes }) => {
if (routes.some((route) => route.ignoreScrollBehavior)) {
return false;
}
if (routes.some((route) => route.scrollToTop)) {
return [0, 0];
}
return true;
};
const render = (renderArgs) => (
<ScrollManager
shouldUpdateScroll={shouldUpdateScrollByPathname}
renderArgs={renderArgs}
>
{/* ... */}
</ScrollManager>
);
You can customize <ScrollManager>
even further by providing a createScrollBehavior
callback that creates the scroll behavior object. This allows using a custom subclass of ScrollBehavior
from scroll-behavior with custom logic. When using a custom createScrollBehavior
callback, you can continue to specify the shouldUpdateScroll
callback as above.
const render = (renderArgs) => (
<ScrollManager
createScrollBehavior={(config) => new MyScrollBehavior(config)}
renderArgs={renderArgs}
>
{/* ... */}
</ScrollManager>
);
FAQs
Scroll management for found
The npm package @catamphetamine/found-scroll receives a total of 1 weekly downloads. As such, @catamphetamine/found-scroll popularity was classified as not popular.
We found that @catamphetamine/found-scroll demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.