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

react-custom-roulette组件数据数组长度超过35时无法渲染奖品的问题求助

react-custom-roulette组件数据数组长度超过35时无法渲染奖品的问题求助

各位大佬好,我最近在用react-custom-roulette做抽奖转盘功能时遇到了个棘手的问题:当奖品数据数组长度在35条及以下时,转盘能正常渲染所有奖品,但一旦超过35条,转盘就完全显示不出奖品了,页面上只剩空的转盘框架。

以下是我的组件核心代码片段,麻烦帮忙排查下问题所在:

import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import axiosInstance from '../../../axiosConfig';
import './wheel.css';
import { getUserInfo } from '../../../user_info';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faChevronDown } from '@fortawesome/free-solid-svg-icons';
import MemoizedWheel from './MemoizedWheel';
import { useUser } from '../../../UserContext';
import WheelAdmin from './WheelAdmin';

const LoadingAnimation = () => (
    <div className="loading-animation">
        <div className="spinner"></div>
        <p>Loading...</p>
    </div>
);

const ButtonLoadingAnimation = () => (
    <div className="button-loading-animation">
        <div className="dot-pulse"></div>
    </div>
);

export default function WheelComponent({
    availablePrizes, // 这个就是出问题的奖品数据数组,超过35条时无法渲染
    // 其他props...
}) {
    const { user } = useUser();
    const [loading, setLoading] = useState(true);
    const [wheelData, setWheelData] = useState([]);

    useEffect(() => {
        // 转换奖品数据格式适配转盘组件
        if (availablePrizes?.length) {
            const formattedData = availablePrizes.map(prize => ({
                option: prize.name,
                style: { backgroundColor: prize.color }
            }));
            setWheelData(formattedData);
            setLoading(false);
        }
    }, [availablePrizes]);

    if (loading) {
        return <LoadingAnimation />;
    }

    return (
        <div className="wheel-container">
            {/* MemoizedWheel是用React.memo包裹的react-custom-roulette组件 */}
            <MemoizedWheel
                data={wheelData}
                // 其他转盘配置项...
            />
            {/* 其他页面元素... */}
        </div>
    );
}

我已经试过的排查步骤:

  • 确认长数组的数据格式和短数组完全一致,没有缺失字段或异常值
  • 检查了网络请求,长数组的数据能正常获取并传入组件
  • 尝试去掉MemoizedWheel的React.memo包裹,问题依然存在

有没有大佬遇到过类似的问题?或者能给一些排查方向和解决方案?

备注:内容来源于stack exchange,提问作者Gabi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.16 12:44:31