React-native-chart-kit: Objects are not valid as a React child

Created on 20 Sep 2018  路  9Comments  路  Source: indiespirit/react-native-chart-kit

When I try to import a library, I get an error

Objects are not valid as a React child (found: object with keys {$$typeof, type, key, ref, props, _owner, _store}). If you meant to render a collection of children, use an array instead.

My project looks like this

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Dimensions} from 'react-native';
import {
    LineChart,
    BarChart,
    PieChart,
    ProgressChart,
    ContributionGraph
} from 'react-native-chart-kit'


const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
  android:
    'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

type Props = {};
export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>Welcome to React Native!</Text>
        <Text style={styles.instructions}>To get started, edit App.js</Text>
        <Text style={styles.instructions}>{instructions}</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

Of course I did
yarn add react-native-chart-kit

Most helpful comment

I found the solution to this problem.
1: Comment import 'babel-polyfill' from first line of react-native-chart-kit index.js

2: Install react-native-svg

Edit:
Also for pieChart, must added import 'babel-polyfill'; into pie-chart.js

All 9 comments

Same here. Looks like importing anything from react-native-chart-kit is enough to cause the error.

Same here. Looks like importing anything from react-native-chart-kit is enough to cause the error.

Yes
The project starts if delete this:

import {
    LineChart,
    BarChart,
    PieChart,
    ProgressChart,
    ContributionGraph
} from 'react-native-chart-kit'

same here, please fix this

+1

+1

Same with:
react-native 0.57.4
react-native-svg 8.0.8
react-native-chart-kit 1.1.9

I found the solution to this problem.
1: Comment import 'babel-polyfill' from first line of react-native-chart-kit index.js

2: Install react-native-svg

Edit:
Also for pieChart, must added import 'babel-polyfill'; into pie-chart.js

I found the solution to this problem.
1: Comment import 'babel-polyfill' from first line of react-native-chart-kit index.js

2: Install react-native-svg

Edit:
Also for pieChart, must added import 'babel-polyfill'; into pie-chart.js

Worked! Thank you!

I found the solution to this problem.
1: Comment import 'babel-polyfill' from first line of react-native-chart-kit index.js

2: Install react-native-svg

Edit:
Also for pieChart, must added import 'babel-polyfill'; into pie-chart.js

Perfect!!! Thank you!!

Was this page helpful?
0 / 5 - 0 ratings