Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

313
Visualizações
Is it possible to somehow change the value of a derived store directly?

I am currently working with SvelteKit.

I have a derived store, which is necessary because it depends on another store. Now I need to change some values in the derived store directly. The problem is that derived stores are not modifyable as far as my understanding goes.

Is there any way to change the value of a derived store directly?

For example if I'd have a derived store called tiles which is an array of objects and I would like to change the property of one of its objects ($tiles[n].x = 'something new')

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can make a derived store writable by simply adding a set function.

You will need either access to the source object from which the value is derived or you need to merge the new value in a way that preserves the relevant object references. (Though in the latter case you may still need to do a dummy reassignment on the parent store, to trigger an update.)

E.g.

const parent = writable({ items: [{ name: 'pochi' }, { name: 'maru' }]});
const items = derived(parent, value => value.items);
items.set = newItems => $parent.items = newItems;

REPL

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda