dimanche 10 novembre 2019

React Checkbox from Postgres Database

I'm getting an array of users from a database table called users. One of the fields is a checkbox with a default of false. I'm not able to change the checkbox. When I got the array from a static page it worked fine, but not working after fetching from database.
Handle Change:

handleChange(id,route) {
   const updatedNetwork = network.map(netw => {
      if (netw.id===id) {
        netw.ischecked = !netw.ischecked
      }
      return netw
    })
    return {
      network:updatedNetwork
    } 
}

Here is how I'm receiving the data:

componentDidMount() {
  fetch('http://localhost:3000/data')
  .then(response => response.json())
  .then(data => {
    this.setState({network:data})})
}
        Server.Js
app.get('/data', (req,res)=> {
    db.select('*').from('users')
    .then(data => {
        console.log(data);
        res.send(data)
    })

})

How can I go about updating the checkboxes, and that when user logs in, it keeps track of the checkboxes that particular user has checked?




Aucun commentaire:

Enregistrer un commentaire