I am pretty a new to React and currently to use the current state of and object as a variable in another array, said array will start filled with 0, and every time someone press the vote button it will store +1 to said array index. I am sure its the wrong way but nevertheless I amtrying to figure out if is possible to use the logic i created.
Thanks for the patience!
import React, { useState } from 'react'
const App = () => {
const anecdotes = [
'If it hurts, do it more often',
'Adding manpower to a late software project makes it later!',
'The first 90 percent of the code accounts for the first 10 percent of the development time...The remaining 10 percent of the code accounts for the other 90 percent of the development time.',
'Any fool can write code that a computer can understand. Good programmers write code that humans can understand.',
'Premature optimization is the root of all evil.',
'Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.',
'Programming without an extremely heavy use of console.log is same as if a doctor would refuse to use x-rays or blood tests when diagnosing patients'
]
const [selected, setSelected] = useState(0)
var ary = new Uint8Array(10);
//console.log('this', this.state);
//show 1 anecdote
//when user press next its generates a random number beetween 0 and 6 to display the anecdote
//issue:
//how to add said random value to my arrays so I can use the array to store the votes of each anecdote
return (
<div>
<h1>{anecdotes[selected]}</h1>
<button onClick={ () => setSelected(Math.floor(Math.random() * 6) ) }>Next Anecdote</button>
<button onClick={ () => ary[selected.state] + 1 }>Vote</button>
<p>votes: {ary[selected.state]}</p>
</div>
)
}
export default App