import { useState, useEffect } from "react";
import db from "./ldbcfg";
import ModifyPDB from "./modifypdb";


const ShowDocs = () => {
  let [flatListItems, setFlatListItems] = useState([]);

  useEffect(() => {
    db.allDocs({ include_docs: true, descending: true })
      .then((results) => {
        let temp = results.rows.map((row) => row.doc);
        setFlatListItems(temp);
      })
      .catch((err) => alert("Unable to get data"));
  }, [flatListItems]);

const handleClick = (doc) => {
<ModifyPDB  />
console.log({doc})
}

return (
  <>
    <ModifyPDB />
    <ul>
      {flatListItems.map(doc => (
        <li key={doc._id} onClick={() => handleClick({doc})} > {doc.task} {doc.description} {doc.assigned2}  </li>
      )) }
    </ul>
  </>
);

};


export default ShowDocs;


