'How can I make the back button goes to the previous step

I am trying to make a quiz app from a json file. How can i make the back button go to the previous step. So I want to make the back button returns to what was previously selected.

 const navigateBack = () => {
    let index = 1;
    axios.get('http://localhost:5000/steps')
      .then((res) => {
        console.log(res);
        const current = res.data.filter((element: any) => destinationstepId !== element.id)

      })
  }
 


 


Solution 1:[1]

If the question ids are sequential define an index as a state using state hook, else you can define history as an array state and move through the array when you are going backward and forward.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ouflak