Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reactive data change #25

Open
megane999 opened this issue Dec 4, 2024 · 1 comment
Open

Reactive data change #25

megane999 opened this issue Dec 4, 2024 · 1 comment

Comments

@megane999
Copy link

I am very new at svelte. How can I change table data reactivly. When I try to assign variable to data I get error "State referenced in its own scope will never update. Did you mean to reference it inside a closure?"

@cdcarson
Copy link

cdcarson commented Dec 4, 2024

Thats a svelte compiler error, probably because you are doing something like:

let { data } = $props();
let rows = $derived(data.rows)
const table = new DataTable({/* settings */})
table.baseRows = rows;

Instead, you can do something like this:

let {data} = $props();
const table = new DataTable({/* settings */})
$effect(() => {
    table.baseRows = data.rows; // or whatever you're returning the rows from the server as
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants