Update json inside db.transaction in react native?

16 Views Asked by At

I have a json with some categories and i'm trying to map this categories trough a table in sqlite db to see which category actually have item and which not. So I can grey out inactive categories.

I am trying something like this..

useEffect(() => {
    for (var i = 0; i < catData.length; i++) {
      db.transaction(tx => {
        tx.executeSql(
          'SELECT * FROM speakers WHERE fileCategory=?',
          [catData[i].cat],
          (tx, results) => {
            var test;
            if (results.rows.length > 0) {
              catData[i].isAvailable = 'yes';
            } else {
              catData[i].isAvailable = 'no';
            }
          },
        );
      });
    }
  }, []);
  console.log(catData); 

No update in json and its probably because I try to update in out of scope?

Problem with using state in this is that the state don't update immediately, always one after?

Any suggestions how I can solve this?

0

There are 0 best solutions below