jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
33.73k stars 2.77k forks source link

Formik v2.x is not working with Preact. #3842

Open alqamabinsadiq opened 1 year ago

alqamabinsadiq commented 1 year ago

Bug report

Current Behavior

I am trying to use Formik v2.x with Preact v10.15.1 but I am facing a bug.

Uncaught 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:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
    at resolveDispatcher (react.development.js:1465:1)
    at useRef (react.development.js:1504:1)
    at useFormik (formik.esm.js:278:29)
    at b.Formik [as constructor] (formik.esm.js:874:1)
    at b.B [as render] (preact.module.js:1:8515)
    at L (preact.module.js:1:6225)
    at P (preact.module.js:1:2156)
    at N (preact.module.js:1:7691)
    at L (preact.module.js:1:6622)
    at P (preact.module.js:1:2156)

Your environment

Software Version(s)
Formik 2.0.1
Preact 10.15.1
TypeScript 4.2.3
Browser chrome
npm/Yarn npm
Operating System macOS
dmmarmol commented 7 months ago

Hi @alqamabinsadiq I'm not sure how to help you with an accurate answer since there's not a link to a repro/sandbox where you could reproduce your issue. However, I can tell you that I'm currently working on a project using formik@2.4.3, vite@4.3.2 and preact@^10.13. and those are working together as expected.

On another hand I was able to reproduce your issue in the above mentioned project when I run my test suite using vitest, so we share the same issue but in different environments