I see the following error for the below code: react-indexed-db-hook.js?v=1ef088ed:2194…
- User
I see the following error for the below code:
react-indexed-db-hook.js?v=1ef088ed:2194 Uncaught TypeError: Cannot assign to read only property 'name' of object '#' at n2.initDB (react-indexed-db-hook.js?v=1ef088ed:2194:18) at main.jsx:10:1 n2.initDB @ react-indexed-db-hook.js?v=1ef088ed:2194 (anonymous) @ main.jsx:10 Show 1 more frame Show lessUnderstand this errorAI content.js:7 Content script loaded
current code (attached):
// src/App.js import React, { useState, useEffect } from 'react'; import { initDB, useIndexedDB } from 'react-indexed-db-hook'; import { DBConfig } from './config/db-config';
// Initialize IndexedDB initDB(DBConfig);
function App() { const { add, update, getAll, deleteRecord } = useIndexedDB('customers'); const [customers, setCustomers] = useState([]); const [selectedCustomer, setSelectedCustomer] = useState(null); const [input, setInput] = useState(''); const [newCustomer, setNewCustomer] = useState(''); const [editingCustomer, setEditingCustomer] = useState(null); const [editName, setEditName] = useState('');
useEffect(() => { loadCustomers(); }, []);
const loadCustomers = async () => { try { const allCustomers = await getAll(); setCustomers(allCustomers); if (allCustomers.length > 0 && !selectedCustomer) { setSelectedCustomer(allCustomers[0]); } } catch (error) { console.error('Error loading customers:', error); } };
const addCustomer = async () => { if (newCustomer.trim()) { try { await add({ name: newCustomer, todos: [] }); await loadCustomers(); setNewCustomer(''); } catch (error) { console.error('Error adding customer:', error); } } };
const startEditingCustomer = (customer) => { setEditingCustomer(customer); setEditName(customer.name); };
const saveCustomerEdit = async () => { if (editName.trim() && editingCustomer) { try { const updatedCustomer = { ...editingCustomer, name: editName }; await update(updatedCustomer); await loadCustomers(); if (selectedCustomer && selectedCustomer.name === editingCustomer.name) { setSelectedCustomer(updatedCustomer); } setEditingCustomer(null); setEditName(''); } catch (error) { console.error('Error updating customer:', error); } } };
const toggleComplete = async (index) => { if (selectedCustomer) { try { const updatedCustomer = { ...selectedCustomer, todos: selectedCustomer.todos.map((todo, i) => i === index ? { ...todo, completed: !todo.completed } : todo ) }; await update(updatedCustomer); await loadCustomers(); setSelectedCustomer(updatedCustomer); } catch (error) { console.error('Error toggling todo:', error); } } };
const addTodo = async () => { if (input.trim() && selectedCustomer) { try { const updatedCustomer = { ...selectedCustomer, todos: [...selectedCustomer.todos, { text: input, completed: false }] }; await update(updatedCustomer); await loadCustomers(); setSelectedCustomer(updatedCustomer); setInput(''); } catch (error) { console.error('Error adding todo:', error); } } };
- Assistant