Skip to content

How to synchronized stores #11449

Answered by coryvirok
ProphetLamb asked this question in Q&A
Discussion options

You must be logged in to vote

I'm not sure if this is what you're after, but I've encountered similar requirements as you describe before. In my scenario, the changes were made by a user to a form. Instead of using bind:value={value} on the input, I added a on:input handler that would update the store and then set the input's value explicitly using a derived store.

eg:

<script>
  const store1 = writable('') // build from local storage
  const store2 = writable('') // build from superforms
  const store3 = derived([store1, store2], ([$store1, $store2]) => {
    // choose value from either store1 or 2
    return $store1 ?? $store2
  })
</script>

synchronized input 1:
<input type='text' on:input={(e) => set(store1, e.ta…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Pandoks
Comment options

Answer selected by ProphetLamb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants