Accessor is a function that returns the stored value in a signal.
type Accessor<T> = () => T;
Unlike React, Solid do not use virtual DOM and does not re-render upon state update. So it needs function calls to get the value of a signal. That is how Solid achieves reactivity.
The createSignal
function returns an array with [Accessor<T>, Setter<T>]
.
const [item, setItem] = createSignal(10);
^
// This is an Accessor<T>
// To get the stored value, you need to invoke the accessor
console.log(item());
The createStore
uses a signal internally and it returns an array with an accessor and a setter. But its accessor uses a proxy object which delegates its property access to the internal signal.
const [todos, setTodos] = createStore([]);
^
// This is a proxied object, not a plain value T
Since only objects and array supports Proxy API, you can only use an object or an array with createStore
function.
The exported type signature of the createStore
function is not derived but manually typed to suppress complications:
function createStore<T extends object = {}>(...[store, options]: {} extends T ? [store?: T | Store<T>, options?: {
name?: string;
}] : [store: T | Store<T>, options?: {
name?: string;
}]): [get: Store<T>, set: SetStoreFunction<T>];
It seems you are trying to store a signal in a store that is how you get that warning but a store value itself is reactive and implements all the necessary API to insert, delete and update items. Avoid storing signals because you would be introducing totally unnecessary abtraction layer.