1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

react

Last updated at Posted at 2023-09-14

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;

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?