BALKANGraph / OrgChartJS

OrgChart JS is a simple, flexible and highly customizable organization chart plugin for presenting the structure of your organization and the relationships in an elegant way.
https://balkan.app/orgchartjs
247 stars 84 forks source link

[React] Is it possibile to use functional component instead of class component ? #806

Open andreatricoli opened 9 months ago

andreatricoli commented 9 months ago

Hi everyone,

in the OrgChart React documentation i can see they use class component, is it possibile to use functional component? if yes, how?

import React, { Component } from 'react';

        export default class Chart extends Component {

            constructor(props) {
                super(props);
                this.divRef = React.createRef();
            }

            shouldComponentUpdate() {
                return false;
            }

            componentDidMount() {
                this.chart = new OrgChart (this.divRef.current , {
                    nodes: this.props.nodes,

                    nodeBinding: {
                        field_0: 'name',
                        img_0: 'img'
                    }
                });
            }

            render() {
                return (
                    <div id="tree" ref={this.divRef}></div>
                );
            }
        }
ZornitsaPesheva commented 9 months ago

We don't have React developers in BALKAN App. Hope somebody else can help.

joshuacos1977 commented 8 months ago

Yes.you can use functional components with React

andreatricoli commented 8 months ago

Hi @joshuacos1977 could you provide me a basic example based on the code i wrote above with both functional component and TypeScript please? Thank you