0

Am new to React and I have a project that am gonna use D3 to create my charts after installing it on my project and create this class:

import React, { Component } from 'react';
var ReactDOM = require('react-dom');
var LineChart = require('react-d3-basic').LineChart;

class TempChart extends Component{
constructor(){
    super();
    this.state={
        generalChartData:{},
        chartSeries:[],
        x:0
    }
}

componentWillMount(){
    fetch("my JSON url was here")
    .then(response=>response.json())
    .then((findresponse)=>{
        this.setState({
            generalChartData:findresponse.feeds.map((feed, i) => parseFloat(feed.field1)),
            chartSeries:[
              {
                field: 'age',
                name: 'Age',
                color: '#ff7f0e',
                style: {
                  "stroke-width": 2,
                  "stroke-opacity": .2,
                  "fill-opacity": .2
                }
              }
            ],
            x:function(d) {
              return d.index;
            }
        })
    })
}

render(){
    return (
        <LineChart
          width= {600}
          height= {300}
          data= {this.state.generalChartData}
          chartSeries= {this.state.chartSeries}
          x= {this.state.x}
        />
    );
}


}
   export default TempChart;

but as results I get this error like this oneerror:

I know that after React version 15.5 you have to import PropTypes from prop-types like below:

import PropTypes from 'prop-types';

or

var PropTypes = require('prop-types');

Now my question is where I have import this, because all D3 files use the old PropType that causes the problem and there's a lot of files in D3 library I cant import the new one in every single one.

This is my package.json file:

{
  "name": "d3app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.4.1",
    "react-d3-basic": "^1.6.11",
    "react-dom": "^16.4.1",
    "react-scripts": "1.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}
S4L4H
  • 402
  • 1
  • 5
  • 21

1 Answers1

0

It looks like it is an issue with the library. It currently is using an old version of React (v 0.14) as a peer-dependency. Like you said 15.5 changes to prop-types. You could fork the library and change prop-types (example: https://github.com/react-d3/react-d3-basic/pull/51/files) but it will need to be fixed by the library maintainers.

Here is an issue going into more detail: https://github.com/react-d3/react-d3-basic/issues/56

biw
  • 3,000
  • 4
  • 23
  • 40