question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React hook invalid when react-chartjs-2 included

See original GitHub issue

Inputting a into a grid component of material UI results in an invalid hook call.

Expected Behavior

Expected there to be a simple line graph in the grid with the example data taken from the chartjs github.

Actual Behavior

Error: Invalid hook call

URL, screen shot, or Codepen exhibiting the issue

// material
import { Container, Box, Typography, Grid } from '@mui/material';
import { useState, React } from 'react';
import { makeStyles } from '@mui/styles';
import { Line } from 'react-chartjs-2';
// components
import Page from '../components/Page';
import DropDown from '../components/DropDown';
import DashBox from '../components/DashBox';

// ----------------------------------------------------------------------

const data = {
  labels: ['1', '2', '3', '4', '5', '6'],
  datasets: [
    {
      label: '# of Votes',
      data: [12, 19, 3, 5, 2, 3],
      fill: false,
      backgroundColor: 'rgb(255, 99, 132)',
      borderColor: 'rgba(255, 99, 132, 0.2)'
    }
  ]
};

const options = {
  scales: {
    y: {
      beginAtZero: true
    }
  }
};

// I think after I build it, we can reuse the filters, like in the dashboard, add a new filter depending on what we want to add
// filling in the filters should be a query that returns the options, ie the cohorts can be done via getting the distinct cohorts
export default function Finances() {
  const optionsCohort = ['Cohort One', 'Cohort Two', 'Cohort Three'];
  const optionsDate = ['One', 'Two'];
  const [componentsFinancial, setComponentsMember = useState([
    {
      title: 'Members',
      urlOne: 'http://api/memberone',
      reportOneTitle: 'Count One',
      urlTwo: 'http://api/membertwo',
      reportTwoTitle: 'Count Two'
    }
  ]);

  return (
    <Page title="Finances">
      <Line data={data} options={options} />
      <Container>
        <Typography variant="h4" sx={{ mb: 5 }}>
          Financial Page
        </Typography>
        <Container marginBottom="10px">
          <Typography marginLeft="5px" variant="h5">
            Filters
          </Typography>
          <Grid
            columns={5}
            sx={{
              display: 'flex',
              flexDirection: 'row',
              alignItems: 'stretch',
              marginTop: '10px',
              marginLeft: '5px',
              justifyContent: 'space-evenly'
            }}
          >
            <Grid item sx={{ pr: 5 }}>
              <DropDown options={optionsDate} title="Date" />
            </Grid>
          </Grid>
        </Container>
        <br />
        <Box
          container
          sx={{ border: 2 }}
          marginLeft="20px"
          pr="20px"
          pb="20px"
          pl="20px"
          width="100%"
        >
          <Typography variant="h3">Financial Dashboard</Typography>
          <DashBox components={componentsFinancial} />
        </Box>
        <Grid>
          <Grid item>
            <Typography>Member Count</Typography>
          </Grid>
        </Grid>
      </Container>
    </Page>
  );
}

Steps to Reproduce

See above.

Your Environment

Browser Name and version: Firefox Operating System and version (desktop or mobile): Windows desktop React dom and React have the same version number of 17.0.2 Code works before the chart is added There are some custom items here (ie DashBox)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
dangreencommented, Dec 10, 2021

@aunshx Hi. Would you please fork this sandbox and reproduce the issue?

1reaction
dangreencommented, Nov 23, 2021

@stebbinscp Hi. Would you please fork this sandbox and reproduce the issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React invalid hook call · Issue #9878 · chartjs/Chart.js - GitHub
Inputting a into a grid component of material UI results in an invalid hook call. Expected Behavior Expected there to be a simple...
Read more >
React Invalid hook call while using chartJS - Stack Overflow
I see errors for 'Invalid Hook Call'. I have checked both versions of react-native and react-dom; versions do not seem to be the...
Read more >
Invalid Hook Call Warning - React
If these react imports resolve to two different exports objects, you will see this warning. This may happen if you accidentally end up...
Read more >
Solving React Hooks' invalid hook call warning - Rob Kendal
Building a React project and have the error 'Hooks can only be called inside the body of a function component'? We'll solve the...
Read more >
react-chartjs-2 - npm
Start using react-chartjs-2 in your project by running `npm i ... React components for Chart.js, the most popular charting library.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found