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

214
Visualizações
how to do it correctly so that when transform one shape, transform another shape in react-konva?

I need to transform one shape to also transform the other so that it fills the free space. How can I do it right in react? Now what I did is not working as it should at all and I have no ideas how to do it differently

Demo: https://stackblitz.com/edit/vitejs-vite-q5jn1d?file=src/Template.jsx

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

0

You don't need to do any magic with Konva nodes and manually touch them. Just work with your react state.

onChange={(newAttrs) => {
  setTemplates((currTemplates) =>
    currTemplates.map((t) => {
      if (t.name === newAttrs.name) {
        return { anchors: t.anchors, ...newAttrs };
      } else if (t.name === 'vertical-p1') {
        return {
          ...t,
          height: newAttrs.y - 10,
        };
      } else if (t.name === 'vertical-p2') {
        return {
          ...t,
          y: newAttrs.height + 10,
          height: 600 - (newAttrs.height + 10),
        };
      }
    })
  );
}}

https://stackblitz.com/edit/vitejs-vite-ynemv6?file=src%2FApp.jsx

Also, you can improve your state more, to have less possible conficts. E.g. instead of defining "rectangles" in your state. You can just have width/height of canvas and y position of divider. The attributes for the shapes can be calculated from the state.

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