Closed btoaelbore closed 1 year ago
you fetch and set signal.value = result
once done?
just want to understand also how does signal works, and what to avoid it
import { signal, effect } from 'usignal'
const name = signal('')
const fname = signal('')
effect(() => {
console.log(fname.value)
effect(() => {
/// this logs 2x
console.log('set name')
/// this execute 2x
new Promise((resolve) => {
setTimeout(() => {
console.log('set name to joe')
name.value = 'joe'
resolve(null)
}, 2000)
})
/// this logs 2x
console.log('Hello')
})
})
fname.value = 'my last name'
outputs
set name
Hello
my last name
set name
Hello
set name to joe
set name to joe
one happens because you register a signal for the outer effect, the second one happens because you change a signal in another effect ... for multipl updates you have batch(callback) but honestly this looks like a request for generic documentation around signals ... there's plenty of that on the internet. Closing as this is not related to this library.
See Preact or Solid.js signals documentation which is well written too, everything in here should work the same.
not sure why I re-opened this ...
basically just wondering if you could guide me how to use usignal with calling rest api? thanks