I have a variable called assignee. Assignee can be one of the three names I listed below in the array. On startup I call a API that returns the current assignee (if an assignee exists). I set the assignee variable to the name I received from the API.
I have a div element that displays the assignee name, when a user clicks this element I want the assignee to change according to the list order. How do I solve this?
Lets say I get Sara from the Api, now when I click the element I want assignee to change to Bill then to Steve, then to Sara. It should go back to the start of the array and re-iterate. Is this the best approach to this problem or are there better ways to solve this?
const users = ["Bill", "Steve", "Sara"];
const [assignee, setAssignee] = useState<string>();
..
const handleAssigneeOnClick = () => {
setAssignee(users[0]);
};
..
<div
className="assignee"
onClick={() => {
handleAssigneeOnClick();
}}
>
<p>{assignee}</p>
</div>