Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

Invalid Hook Call in React Js #340

Open
Chaitanya-podilapu opened this issue Apr 21, 2021 · 4 comments
Open

Invalid Hook Call in React Js #340

Chaitanya-podilapu opened this issue Apr 21, 2021 · 4 comments

Comments

@Chaitanya-podilapu
Copy link

I'm trying to handle an operation from different re-usable component.

import { useState } from 'react';

export function DatagridControl(dataToCntrlDataGrid) {

  const [checkBoxChecked, setCheckBoxChecked] = useState([]);
  const checkBoxSelectionModalChange = (itm) => {
    setCheckBoxChecked(itm.selectionModel);
    console.log(checkBoxChecked)
  }

  return {
      checkBoxSelectionModalChange
  }
}

Upon using useState() i'm getting invalid hook call. I've gone through react documentation and this thread and nothing seems helpful and clear.

One thing i'm sure of is that i'm having a duplicate react, that i found by doing the below as stated in documentation.

`window.React1 = require('react');

// Add this in your component file
require('react-dom');
window.React2 = require('react');
console.log(window.React1 === window.React2);`
@andybustamante
Copy link

I'm running into the same issue. Did you resolve this?

@rap0so
Copy link

rap0so commented May 21, 2021

Guys, have you ever tried this?

@hergaiety
Copy link

I ran into this as well and after lots of research I wrote up this article about solving it https://gaiety.life/react-library-and-peer-dependency-woes/

In short, it has to do with react and react-dom being in devDepenedencies or dependencies, which this tool does by default. Keep it only in peerDependencies.

@christopher-caldwell
Copy link

This is a non starter. The example uses link to share the same instance of React. This is not practical if your target is not near your source. For me, there's a repo that has all of the shared UI libs. The target consumer is another repo. This is of course not this library's problem, but not being able to use this with flexibility is a problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants