简体   繁体   中英

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

I'm using create-react-app to get my app started, and I want to use d3 in my components. I'm using node 6.3.1. I have run

npm install d3 --save

and can see d3 in my package.json. So why don't I have d3? Here's my component class; it 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

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

import * as d3 from 'd3'

Or just import the functions you intend on using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM