You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求提供AutoAnimate FormKit官网动画列表组件的React示例代码

AutoAnimate React版本示例说明

确实存在React版本的示例,你提到的GitHub仓库里的dropdown.jsx文件就是完整的React实现示例。

如果要实现官网那种列表动画效果,核心是用AutoAnimate提供的useAutoAnimate钩子,给列表容器添加动画能力。这里给你一个简化版的实现参考:

import { useState } from 'react'
import { useAutoAnimate } from '@formkit/auto-animate/react'

function AnimatedList() {
  const [items, setItems] = useState(['项目1', '项目2', '项目3'])
  const [parent] = useAutoAnimate()

  const addItem = () => {
    setItems([...items, `新项目${items.length + 1}`])
  }

  const removeItem = (index) => {
    setItems(items.filter((_, i) => i !== index))
  }

  return (
    <div ref={parent}>
      <button onClick={addItem}>添加项目</button>
      {items.map((item, index) => (
        <div key={index} style={{ padding: '8px', margin: '4px 0', border: '1px solid #eee' }}>
          {item}
          <button onClick={() => removeItem(index)} style={{ marginLeft: '8px' }}>删除</button>
        </div>
      ))}
    </div>
  )
}

export default AnimatedList

这段代码实现了列表项添加和删除时的平滑动画,和官网展示的效果逻辑一致。你可以直接安装@formkit/auto-animate包后运行这段代码验证效果。

内容的提问来源于stack exchange,提问作者n_d22

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 10:25:25