Skip to content

Commit ca6e5d7

Browse files
committed
Don't directly reference local state
In svelte 5, $state referenced locally is not reactive, because of how evaluation occurs. Svelte will warn about this at runtime (and does so here) To make it reactive locally, we use property getters, to ensure we always return the latest state.
1 parent b5339c5 commit ca6e5d7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/svelte-table/src/createTable.svelte.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ export function createTable<
2525
tableOptions,
2626
{
2727
_features,
28-
state: { ...state, ...tableOptions.state },
28+
get state() {
29+
return { ...state, ...tableOptions.state }
30+
},
2931
mergeOptions: (
3032
defaultOptions: TableOptions<TFeatures, TData>,
3133
newOptions: Partial<TableOptions<TFeatures, TData>>,
@@ -40,7 +42,9 @@ export function createTable<
4042
function updateOptions() {
4143
table.setOptions((prev) => {
4244
return mergeObjects(prev, tableOptions, {
43-
state: mergeObjects(state, tableOptions.state || {}),
45+
get state() {
46+
return mergeObjects(state, tableOptions.state || {})
47+
},
4448
onStateChange: (updater: any) => {
4549
if (isFunction(updater)) state = updater(state)
4650
else state = mergeObjects(state, updater)

0 commit comments

Comments
 (0)