0.0.1 • Published 3 years ago

react-waterfall-scroll v0.0.1

Weekly downloads
-
License
-
Repository
github
Last release
3 years ago

react-waterFall

react轻量级瀑布流组件

参数

参数说明类型默认值
col列数,必填number or string3
horizontalSpacing水平间距number or string10
verticalSpacing垂直间距number or string10
waterFallBoxStyle瀑布流容器样式覆盖Object{}
width宽度,建议填写,不写则自适应number or string'unset'
useWindow触底加载以body作为参照booleanfalse
limitHeight触底加载触发高度number or string50
CardComponent卡片组件React.ComponentType() => null
data循环数据Array[]
onReachBottom数据加载钩子函数Function() => { }

示例

const getDefaultData = () => {
  return Array.from(Array(10), (v, k) => {
    return 200 + Math.random() * 200
  })
}


function CardComponent(props: any) {
  return (
    <div className='card-box' style={{ height: props.data }}>
      <div className='card-content'>{props.data}</div>
    </div>
  )
}

function App() {
  const [data, setData] = useState<Array<any>>(getDefaultData())

  const onReachBottom = useCallback(() => {
    setTimeout(() => {
      setData((pre) => {
        return [ ...pre,  ...getDefaultData() ]
      })
    }, 300)
  }, [data])

  const waterFallProps = {
    col: 3,
    horizontalSpacing: 10,
    verticalSpacing: 10,
    waterFallBoxStyle: {},
    width: 'unset',
    useWindow: false,
    limitHeight: 50,
    CardComponent,
    data,
    onReachBottom,
  }

  return (
    <>
      <WaterFall {...waterFallProps} />
      <button onClick={onReachBottom}>12312312312313</button>
    </>
  )
}