Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with Preact #54

Open
mrbrianevans opened this issue Oct 2, 2021 · 2 comments
Open

Not working with Preact #54

mrbrianevans opened this issue Oct 2, 2021 · 2 comments

Comments

@mrbrianevans
Copy link

I am trying to use this in a Preact app, but can't get it to work.

TypeError: createRef is not a function

I have compat aliases set up in snowpack config:

alias: {
    react: 'preact/compat',
    'react-dom': 'preact/compat',
  }

and typescript paths in tsconfig.json:

"paths": {
      "react": ["node_modules/preact/compat/"],
      "react-dom": ["node_modules/preact/compat/"]
    }

I created the factory as recommended in the docs, but still get the above mentioned error.

Has anyone else successfully used react-hint with the latest version of preact? (v10.5.14 at time of writing).

Any ideas what I could do?

Many thanks,
Brian

@JuliusHenke
Copy link

JuliusHenke commented Jan 5, 2022

@mrbrianevans Maybe you have missed the change in what parameters need to be passed to ReactHintFactory. Taken from README.md:

// Preact
import {h, Component, createRef} from 'preact'
import ReactHintFactory from 'react-hint'
const ReactHint = ReactHintFactory({createElement: h, Component, createRef})

This fixed it for me on preact v10.3.4.

@theoparis
Copy link

Unfortunately, this gives the following error in typescript.

Argument of type '{ createElement: typeof h; Component: typeof Component; createRef: <T = any>() => RefObject<T>; }' is not assignable to parameter of type 'typeof React'.
  Type '{ createElement: typeof h; Component: typeof Component; createRef: <T = any>() => RefObject<T>; }' is missing the following properties from type 'typeof React': createPortal, render, hydrate, unmountComponentAtNode, and 33 more.ts(2345)

A workaround is to use the following type cast, although it is pretty ugly.

const ReactHint = ReactHintFactory({
    createElement: h,
    Component,
    createRef
} as unknown as Parameters<typeof ReactHintFactory>[0]);

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

No branches or pull requests

3 participants