spotlight icon indicating copy to clipboard operation
spotlight copied to clipboard

Invalid Hook Call Error when Creating Custom Integration Tab for Spotlight

Open DanSnow opened this issue 1 year ago • 4 comments

I am trying to create a custom integration tab for Spotlight. However, Spotlight bundles React into its code, causing me to encounter an "invalid hook call" error whenever I use a React component that utilizes hooks.

Environment

"@spotlightjs/spotlight": "1.2.7"

Steps to Reproduce

  1. make a simple integration plugin with component like
 function TabContent () {
    useEffect(() => { console.log('test') }, [])
    return <div />
 }

Expected Result

Successfully create an integration tab

Actual Result

image

DanSnow avatar Jan 27 '24 05:01 DanSnow

Hi @DanSnow can you please share the steps you used? need some more context to check what goes wrong. Thanks

Shubhdeep12 avatar Jan 27 '24 06:01 Shubhdeep12

Hi @Shubhdeep12 ,

I've created a minimal reproduction at https://github.com/DanSnow/spotlight-custom-integration-issue.

Reproduction Steps:

  1. Clone this repo.
  2. Run 'yarn install'.
  3. Run 'yarn dev'.
  4. Open the page.

Expected Result: The Spotlight button displays normally.

Actual Result: It does not display, and there is an 'invalid hook' error in the console.

DanSnow avatar Jan 27 '24 07:01 DanSnow

I'm wondering if its simple to re-export react here (though that feels dirty). Alternatively we'll have to provide some way to swap out the underlying react implementation. I'm not entirely sure what'd be cleanest here, or if theres some prior art of other folks trying to sandbox react in the same way we are.

dcramer avatar Jan 29 '24 18:01 dcramer

Anyway to work around this in the short term?

Edit: was able to work around by using class components

MisterJimson avatar Feb 09 '24 15:02 MisterJimson

We deprecated custom integrations so closing.

BYK avatar Sep 26 '25 20:09 BYK