solid icon indicating copy to clipboard operation
solid copied to clipboard

Should there be a version of useStore & useSignal which return a [accessor, setter] pair?

Open btakita opened this issue 3 years ago • 1 comments

A [accessor, setter] pair would be useful for situations where solid components use both the accessor & setter. The atom.set() function could be setter but returning the [accessor, setter] pair is more idiomatic to Solidjs.

If we were to go this route, I propose the following types:

import type { Store } from 'solid-js/store'
import type { ReadableAtom, WritableAtom } from 'nanostores'
declare function useSignal<Value>(atom: WritableAtom<Value>):[()=>Value, (val:Value)=>void];
declare function useStore<Value>(atom: WritableAtom<Value>):[Store<Value>, (val:Value)=>void];
declare function useMemo<Value>(atom: ReadableAtom<Value>):()=>Value

btakita avatar Jan 01 '22 21:01 btakita