Skip to content

Commit 60d5c51

Browse files
authored
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, the docs recommend using a closure, which is what we do here.
1 parent b5339c5 commit 60d5c51

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ export function createTable<
2020
let state = $state<Partial<TableState<TFeatures>>>(
2121
getInitialTableState(_features, tableOptions.initialState),
2222
)
23-
23+
const getState = () => state
24+
2425
const statefulOptions: TableOptions<TFeatures, TData> = mergeObjects(
2526
tableOptions,
2627
{
2728
_features,
28-
state: { ...state, ...tableOptions.state },
29+
state: { ...getState(), ...tableOptions.state },
2930
mergeOptions: (
3031
defaultOptions: TableOptions<TFeatures, TData>,
3132
newOptions: Partial<TableOptions<TFeatures, TData>>,

0 commit comments

Comments
 (0)