Skip to content

Instantly share code, notes, and snippets.

@devotdev
Last active October 31, 2024 14:20
Show Gist options
  • Select an option

  • Save devotdev/97fdb2877f23e8bb777d4c12c4faef06 to your computer and use it in GitHub Desktop.

Select an option

Save devotdev/97fdb2877f23e8bb777d4c12c4faef06 to your computer and use it in GitHub Desktop.
React signal example with doubled amount using preact/signals library
import { signal, computed, effect } from '@preact/signals';
const count = signal(0);
const doubled = computed(() => count.value * 2);
effect(() => console.log('Doubled has value: ', doubled.value))
count.value++;
// OUTPUT VALUES:
// Doubled has value 0
// Doubled has value 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment