-
-
Save devotdev/a9ecf31681e96fb1eb07f03af9014b96 to your computer and use it in GitHub Desktop.
React signal example with fruits using preact/signals libraryname
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { signal, computed, effect } from '@preact/signals'; | |
const fruits = signal(['banana', 'mango', 'orange', 'kiwi']); | |
const fruitsWithW = computed(() => fruits.value.filter(fruit => fruit.includes('w'))); | |
fruits.value = [...fruits.value, 'watermelon']; | |
effect(() => console.log(fruitsWithW.value)) | |
// OUTPUT VALUES: | |
// ['kiwi'] | |
// ['kiwi', 'watermelon'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment