d3.event is null in a ReactJS + d3JS component

前端 未结 5 1156
北恋
北恋 2020-12-17 20:22

I\'m using ReactJS, d3JS and ES6 to create an org chart. I can create the chart and see it. But I want to add the zoom behavior to the chart, so I used

5条回答
  •  春和景丽
    2020-12-17 21:09

    If you're using React, Babel or Webpack and d3.js v4, it looks like you need to import event from d3-selection in order to use d3.event

    import * as d3 from 'd3';
    import {event as currentEvent} from 'd3-selection';
    

    You can now use currentEvent the same way you'd use d3.event. See https://github.com/d3/d3/issues/2733 for more information.

提交回复
热议问题