
Security News
pnpm 10.16 Adds New Setting for Delayed Dependency Updates
pnpm's new minimumReleaseAge setting delays package updates to prevent supply chain attacks, with other tools like Taze and NCU following suit.
better-scroll-react
Advanced tools
让better-scroll的使用更简单。
import BetterScroll from 'better-scroll-react'
function Index() {
return (
<>
<div style={{height: 400, border: '1px solid'}}>
<BetterScroll>
<div style={{
height: 600,
background: 'red'
}}>
Hello better-scroll-react
</div>
</BetterScroll>
</div>
</>
)
}
注意:better-scroll-react
不是better-scroll的React实现,只是在better-scroll基础上包装了一层,让better-scroll的使用更简单:
BetterScroll
实例的创建和销毁;wrapper
,再也不用担心BetterScroll 初始化了, 但是没法滚动
。npm install @better-scroll/core better-scroll-react
import BetterScroll from 'better-scroll-react'
function Index() {
return (
<>
<div style={{height: 400, border: '1px solid'}}>
<BetterScroll>
<div style={{
height: 600,
background: 'red'
}}>
Hello better-scroll-react
</div>
</BetterScroll>
</div>
</>
)
}
better-scroll-react
组件的属性以及属性默认值逻辑同better-scroll 配置项
BetterScroll
实例通过ref
可以获取BetterScroll
实例
import BetterScroll from 'better-scroll-react'
import { useEffect, useRef } from 'react'
function Index() {
const scrollRef = useRef();
useEffect(() => {
scrollRef.current.on('scrollStart', () => {
console.log('Begin scroll')
})
}, [])
return (
<>
<div style={{height: 400, border: '1px solid'}}>
<BetterScroll ref={scrollRef}>
<div style={{
height: 600,
background: 'red'
}}>
Hello better-scroll-react
</div>
</BetterScroll>
</div>
</>
)
}
插件使用方式同better-scroll。
import BetterScroll from 'better-scroll-react'
import Pullup from '@better-scroll/pull-up'
import { useEffect, useRef } from 'react'
const plugins= [
// 插件和插件配置
[Pullup, { pullUpLoad: true }]
]
function Index() {
const scrollRef = useRef();
useEffect(() => {
scrollRef.current.on('pullingUp', () => {
console.log('pullingUp')
setTimeout(() => {
scrollRef.current.finishPullUp()
}, 1000)
})
}, [])
return (
<>
<div style={{height: 400, border: '1px solid'}}>
<BetterScroll ref={scrollRef} plugins={plugins}>
<div style={{
height: 600,
background: 'red'
}}>
Hello better-scroll-react
</div>
</BetterScroll>
</div>
</>
)
}
插件的配置属性不能直接传给better-scroll-react
组件,必须在plugins
属性里传递(如上面DEMO)
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
addContentNode | boolean | true | 是否给滚动内容包裹个div 节点,处理多子节点的场景 |
className | string | 无 | wrapper容器className |
style | Object | 无 | wrapper容器style |
plugins | Array<> | 无 | BetterScroll插件,传入格式:[PullDown] , [PullDown, {pullDownRefresh: true}] |
其他属性同BetterScroll 2.0 Options |
FAQs
React component for wrapping better-scroll library.
We found that better-scroll-react 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.
Security News
pnpm's new minimumReleaseAge setting delays package updates to prevent supply chain attacks, with other tools like Taze and NCU following suit.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.