首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:'array-move‘不包含默认导出(作为’move‘导入)

错误:'array-move‘不包含默认导出(作为’move‘导入)
EN

Stack Overflow用户
提问于 2021-09-07 09:57:59
回答 2查看 52关注 0票数 0

在文件夹中:./src/Components/Timeline/ReorderingModalNodes/use-position-reorder.js出现问题标题中提到的错误。但是array-move是一个包,所以我不确定如何修复它。如果问题不清楚,请让我知道,这样我就可以编辑更多信息

代码如下:

代码语言:javascript
复制
import { useState, useRef } from 'react';
import { clamp, distance } from 'popmotion';
import move from 'array-move';

export function usePositionReorder(initialState) {
  const [order, setOrder] = useState(initialState);

  // We need to collect an array of height and position data for all of this component's
  // `Item` children, so we can later us that in calculations to decide when a dragging
  // `Item` should swap places with its siblings.
  const positions = useRef([]).current;
  const updatePosition = (i, offset) => (positions[i] = offset);

  // Find the ideal index for a dragging item based on its position in the array, and its
  // current drag offset. If it's different to its current index, we swap this item with that
  // sibling.
  const updateOrder = (i, dragOffset) => {
    const targetIndex = findIndex(i, dragOffset, positions);
    if (targetIndex !== i) setOrder(move(order, i, targetIndex));
  };

  return [order, updatePosition, updateOrder];
}

const buffer = 30;

export const findIndex = (i, yOffset, positions) => {
  let target = i;
  const { top, height } = positions[i];
  const bottom = top + height;

  // If moving down
  if (yOffset > 0) {
    const nextItem = positions[i + 1];
    if (nextItem === undefined) return i;

    const swapOffset =
      distance(bottom, nextItem.top + nextItem.height / 2) + buffer;
    if (yOffset > swapOffset) target = i + 1;

    // If moving up
  } else if (yOffset < 0) {
    const prevItem = positions[i - 1];
    if (prevItem === undefined) return i;

    const prevBottom = prevItem.top + prevItem.height;
    const swapOffset = distance(top, prevBottom - prevItem.height / 2) + buffer;
    if (yOffset < -swapOffset) target = i - 1;
  }

  return clamp(0, positions.length, target);
};
EN

回答 2

Stack Overflow用户

发布于 2021-09-07 10:03:39

正如错误所述,可能array-move不包含缺省导出,而只包含命名导入。

你能试试import { move } from 'array-move';吗?

还有,这就是https://www.npmjs.com/package/array-move吗?我在文档中看不到move方法。

票数 2
EN

Stack Overflow用户

发布于 2021-09-07 10:05:22

因为在array-move中只有2个方法

代码语言:javascript
复制
arrayMoveMutable
arrayMoveImmutable

不能导入移动

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69086102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档