I've been following a tutorial about update a value, it increments the value when the user clicks a button.
But, I have the JSON object value to be updated. The value should be updated when the user clicks a button and vice versa. After I tried to implements following the example, it not changed. Here's my code:
1. onClick:
<div>
Point: {item.point} 
<button onClick={() => setCount(item.point + 1)} class="btn"><i class="fa fa-arrow-up"></i></button>
<button onClick={() => setCount(item.point - 1)} class="btn"><i class="fa fa-arrow-down"></i></button>
</div>
2. useState:
const [count, setCount] = useState(0);
3. comments.json:
{
"id": "fa1ca3c1-cc1e-4ed9-86b8-f60d8312d499",
"author": "Neal Topham",
"avatar": "http://lorempixel.com/100/100/people/1/",
"date": "2017-02-08T00:30:05.552Z",
"message": "Mungkin ada fenomena paranormal yang tidak bisa dijelaskan. Lebih baik nyala mati sendiri daripada tidak nyala sama sekali",
"point": 3,
}
4. Tutorial Link: