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

155
Visualizações
Force rerender of react component in retejs controller

I want to create a node that previews previous values using react, rete.js, and Chart JS.

But change of props or call to update method is not refreshing the component.

How can I fix that?

Relevant code below or codesandbox link with boilerplate

class ChartController extends Rete.Control {
    static component = ({ data }) => {
        console.log("Rerender")
        return <Line data={data} ></Line>
    }

    addValue(value) {
        this.props.data.datasets[0].data.push({ y: value, x: new Date().getTime() })
        this.update()
    }

    constructor(key) {
        super(key)
        this.render = 'react';
        this.component = ChartController.component
        this.props = {
            data: {
                "datasets": [
                    {
                        "fill": true,
                        "data": [{ "y": 0, "x": 1646927922557 }, { "y": 0, "x": 1646927926815 }, { "y": 1, "x": 1646927927804 }, { "y": 2, "x": 1646927927983 }, { "y": 3, "x": 1646927928133 }, { "y": 4, "x": 1646927928287 }, { "y": 5, "x": 1646927928429 }, { "y": 6, "x": 1646927928580 }, { "y": 7, "x": 1646927928726 }, { "y": 8, "x": 1646927928855 }, { "y": 9, "x": 1646927929022 }, { "y": 10, "x": 1646927929142 }],
                        "backgroundColor": "rgba(255, 99, 132, 0.2)",
                        "borderColor": "rgba(255, 99, 132, 1)",
                        "borderWidth": 1
                    }],
            }
        }
    }
}

export class Preview extends Rete.Component {
    constructor() {
        super("Preview")
    }

    builder(node) {
        this.node = node
        this.max_size = 1_000
        this.preview = new ChartController('preview')

        return node
            .addInput(new Rete.Input('num', "Input", numSocket, false))
            .addOutput(new Rete.Output('num', "Output", numSocket, false))
            .addControl(this.preview)
    }

    worker(_node, inputs, outputs) {
        const base = inputs['num']
        const val = (base.length == 0 || typeof base[0] != 'number') ? 0 : base[0]
        this.preview.addValue(val)
        outputs['num'] = val
        return outputs
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In the linked CodeSandbox there are two different problems.

  1. The Line component from react-chartjs-2. only supports a “category” x-axis, and x values must be strings. In the CodeSandbox I link after the explanation I simply String(…)-ed them just to make it work.
  2. The data (and props) was being mutated directly. This is usually a by “no” in React-land.

You can find a working example here: https://codesandbox.io/s/rete-js-react-render-forked-prdyof?file=/src/rete.jsx

Also, probably you want to use another charts library if you want to control both the x- and y-axis of your line chart.

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