Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda