// components/RandomSelector.js import React from 'react'; const RandomSelector = ({ students, onSelect = () => { } }) => { const selectRandomStudent = () => { if (students.length === 0) return; const randomIndex = Math.floor(Math.random() * students.length); const selectedStudent = students[randomIndex]; // 确保 onSelect 是一个函数 if (typeof onSelect === 'function') { onSelect(selectedStudent); } else { console.error('onSelect is not a function'); } }; return (
); }; export default RandomSelector;