import React, { useState } from 'react';
interface ArrayCounterProps {
initialArray: any[]; // ここで配列の型を指定してください
}
const ArrayCounter: React.FC = ({ initialArray }) => {
const [array, setArray] = useState(initialArray);
const [count, setCount] = useState(initialArray.length);
const [currentIndex, setCurrentIndex] = useState(0);
const handlePrevClick = () => {
setCurrentIndex((prevIndex) => Math.max(prevIndex - 1, 0));
};
const handleNextClick = () => {
setCurrentIndex((prevIndex) => Math.min(prevIndex + 1, count - 1));
};
const currentElement = array[currentIndex];
return (
要素数: {count}
前へ
{currentElement}
次へ
);
};
export default ArrayCounter;