Reputation: 838
I have imported useStats
into my index page but when I use it it breaks gatsby/react and I get this error:
Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
This could happen for one of the following reasons:
I tried to trouble shoot using this from the site:
// Add this in node_modules/react-dom/index.js
window.React1 = require('react');
// Add this in your component file
require('react-dom');
window.React2 = require('react');
console.log(window.React1 === window.React2);
But I got back true. Here is my code:
import React, { useState } from "react";
import { Link } from "gatsby";
// components
import Layout from "../components/Layout/Layout";
import SEO from "../components/seo";
import IndexComponent from "../components/IndexComponent/IndexComponent";
const IndexPage = () => {
const [sku] = useState();
return (
<Layout>
<SEO title="Home" />
<IndexComponent />
</Layout>
);
};
export default IndexPage;
Upvotes: 1
Views: 370
Reputation: 17249
1.) you need [sku, setSku] = useState()
.
2.) Where are you rendering IndexPage?
Are you doing IndexPage()
instead of <IndexPage />
?
Upvotes: 1
Reputation: 838
I think It is a terminal Issue with windows.
Seams to work fine with bash.
Upvotes: 0