I want to create a method taking an array
as parameter, that renders two divs, one displaying the text of the object in the array, second allows user to go to the next text in the array.
However, even though the variable is being incremented the div
doesn't re-render with new text. How I can do this without creating a lot of code like redux?
Code below:
const array = [{text: '1st text'}, {text: "2nd text"}]
dialogueReceiver = (array, i) =>{
let i = 0;
const increment = () =>{
i++;
}
return(
<div>
<div> {array[i].text} </div>
<div onClick={ () => increment()}> NEXT </div>
</div>
)
}