Skip to content

Collection的onBatchResize会闭包state #75

@yuningjiang123

Description

@yuningjiang123

可在repo内example/collection.tsx文件的onBatchResize函数内添加console.log({ size1 }),观看demo效果。当多次发生resize时,打印的size1始终是第一次渲染时的size1。

原因应该是src/SingleObserver/index.tsx内,onInternalResize用useCallback做了持久化,如果onCollectionResize发生了更新则无法通知onInternalResize做出更新。因此应该加一个

const onCollectionResizeRef = React.useRef(onCollectionResize); onCollectionResizeRef.current = onCollectionResize;

之类的改造;

或者src/Collection.tsx对onBatchResize用ref包装,onResize依赖传空数组做成持久化。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions