I need to move the items on the list up when they are click. I have tried updating the state but it didn't work.
import React from "react";
import ReactDOM from "react-dom";
// props is an array of items
const List = (props) => {
// Move the items up when they are clicked
const { items } = props;
const [index, setIndex] = React.useState(0);
const handleChange = (index) => {
// move the item up after it is clicked
setIndex(index + 1);
};
return (
<ul>
{items.map((item, index) => (
<li key={index} onClick={() => handleChange(index)}>
{item}
</li>
))}
</ul>
);
};