Replies: 2 comments
-
Using a tuple is the smallest convenient way to return two items at once. You can write your own abstraction over createSignal: const createSignalObj = (...args) => {
const [get, set] = createSignal(...args);
return { get, set };
}; |
Beta Was this translation helpful? Give feedback.
0 replies
-
If you want the latter syntax, this is already done internally in the store part of Solid: solid/packages/solid/store/src/store.ts Lines 122 to 136 in 17763fa So you could do something like this (to make your marginally nicer variant work): import { Accessor, createSignal, Setter, } from 'solid-js';
import { SignalOptions } from 'solid-js/types/reactive/signal';
function createSignalCombined<T>(value: T, options: SignalOptions<T>) {
const [get, set] = createSignal(value, options);
(get as Accessor<any> & { set: Setter<T> }).set = set;
return get as Accessor<any> & { set: Setter<T> };
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
What do y'all think of adding
.get
as a synonym forthis[0]
and.set
as a synonym forthis[1]
in the return value ofcreateSignal
?For example, I currently write:
but it would be (marginally) nicer to write
Beta Was this translation helpful? Give feedback.
All reactions