unicef / react-org-chart

Component for displaying an org chart for a large organization. Supports lazy load and export.
https://unicef.github.io/react-org-chart/
241 stars 122 forks source link

Error: TypeError: Cannot read property 'tree' of undefined #13

Open Akrion opened 4 years ago

Akrion commented 4 years ago

I am trying to use this module in a project and with the provided demo tree I can not load the component at all. Issues I noticed are:

TypeError: Cannot read property 'tree' of undefined

My whole App.js is:

import React from 'react';
import './App.css';
import OrgChart from '@unicef/react-org-chart'

let tree = {
  id: 1,
  person: {
    id: 1,
    avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/spbroma/128.jpg',
    department: '',
    name: 'Jane Doe',
    title: 'CEO',
    totalReports: 1
  },
  hasChild: true,
  hasParent: false,
  isHighlight: true,
  children: [
    {
    id: 2,
    person: {
      id: 2,
      avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/spbroma/128.jpg',
      department: '',
      name: 'John Foo',
      title: 'CTO',
      totalReports: 0
    },
    hasChild: false,
    hasParent: true,
    isHighlight: false,
    children: []
  }]
}

function App() {
  return (
    <div className="App">
      <OrgChart tree={tree} />
    </div>
  );
}

export default App;

my-app.zip

Akrion commented 4 years ago

I was able to make some progress on this by adding exactly the 3.5.17 d3 version to the package.json. D3 latest version is not compatible.

itsnotme01 commented 4 years ago

Thank you, I had the same error and it solved it, did you found a way to display something?

tdozi commented 4 years ago

I believe this is related to layout method in d3: https://github.com/unicef/react-org-chart/issues/11