Create-react-app and d3 - Why is d3 undefined?

I am using the create-react-app application to run my application and I want to use d3 in my components. I am using node 6.3.1. I launched

npm install d3 --save

and can see d3 in my package.json. So why don't I have d3? Here is my component class; he reports that d3 is undefined.

import React from 'react'
import d3 from 'd3'

var Grid = React.createClass({
  render: () => {
    console.log('d3', d3) // reports "d3 undefined"
    return (<div/>)
  }
})

export default Grid
+4
source share
1 answer

d3 is not a top-level export, but you can import everything and save it in the d3 namespace

import * as d3 from 'd3'

Or simply import the features you intend to use.

+10
source

Source: https://habr.com/ru/post/1658625/


All Articles