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
Using React Hooks + Typescript #2207
Comments
@AmitFeldman - this is likely happening because of duplicated react libraries (in the component and in the consuming application). Try following the instructions here: https://docs.bit.dev/docs/react-guidelines#add-react-libraries-as-peer-dependencies-with-relaxed-versions |
@Tallyb The component is public, you can see there that the dep is configured correctly. |
@Tallyb @GiladShoham Just in case I also tried to add react-dom to the peer dependencies (v0.0.11 of this component: https://bit.dev/ofek/catdog/hook-test) as written in the linked docs. Still doesn't work, anyone have any ideas? I saw that this problem also exists on a bunch of other bit hook+ts components. |
odd. hooks have worked for me without any problems, and when I paste the same code in the playground it works without errors. looking into this.. |
ok no lead so far. I can't see any difference between the components, why is it rendering there? |
Hi KutnerUri, |
huh? this is unexpected!! can you describe it? For my fork, I only imported I also made these changes, but they should not make a difference:
here is the diff:
Full package json: {
"name": "@bit/kutner.temp.hook-test",
"version": "0.0.12",
"homepage": "https://bit.dev/kutner/temp/hook-test",
"main": "dist/HookTest.js",
"dependencies": {},
"devDependencies": {},
"peerDependencies": {
"react-dom": "^16.11.0",
"react": "^16.11.0",
"@types/react": "16.9.11",
"@types/react-dom": "16.9.4"
},
"license": "SEE LICENSE IN LICENSE",
"bit": {
"env": {
"compiler": {
"bit.envs/compilers/react-typescript@3.1.23": {
"rawConfig": {
"tsconfig": {
"compilerOptions": {
"lib": [
"dom",
"es2015"
],
"jsx": "react"
},
"include": [
"./**/*"
]
},
"development": false,
"copyPolicy": {
"ignorePatterns": [
"package.json",
"package-lock.json",
"tsconfig.json"
],
"disable": false
},
"useExperimentalCache": false
},
"options": {},
"files": {}
}
}
},
"overrides": {
"dependencies": {
"react": "-"
},
"peerDependencies": {
"react": "^16.9.0",
"react-dom": "^16.9.0"
}
}
}
} |
If you look at the console output of the two component, you can see that ours build with all the node module dependenies while yours build your source file only. |
You are correct! @orensj / @AmitFeldman - Try updating compiler to latest version. (3.1.23 -> latest) forked: ____ _ _ _ _ _ _____ _
| __ )(_) |_ / | || | |___ / |
| _ \| | __| | | || |_ / /| |
| |_) | | |_ | |__ _| / /_| |
|____/|_|\__| |_| |_|(_)_/(_)_|
built Files:
src/HookTest/HookTest.d.ts
src/HookTest/HookTest.js Original___ _ _ _ _ _ _____ _
| __ )(_) |_ / | || | |___ / |
| _ \| | __| | | || |_ / /| |
| |_) | | |_ | |__ _| / /_| |
|____/|_|\__| |_| |_|(_)_/(_)_|
built Files:
HookTest.d.ts
HookTest.js
node_modules/csstype/index.d.ts
node_modules/csstype/index.js.flow
node_modules/csstype/LICENSE
node_modules/csstype/README.md
node_modules/js-tokens/CHANGELOG.md
node_modules/js-tokens/index.js
... |
@orensj nice catch. |
@GiladShoham |
Yes, that helps a lot! @davidfirst @qballer |
@GiladShoham , the Typescript compiler had this exact issue on Windows. It was saving the node_modules into the dists. It has been fixed a few months ago, so the latest version should be fine. |
@davidfirst Thanks. |
I upgrade the react-typescript compiler to 3.1.26 and use --no-cache build option, and that didn't fix the problem. |
@orensj Thanks for the update. |
@orensj , are you sure you're the latest compiler version is attached to the component in question? I'd be happy to try myself, but I got a bit lost in the thread. Are we talking about the same component in the description (https://bit.dev/ofek/catdog/hook-test)? |
@davidfirst I updated https://bit.dev/ofek/catdog/hook-test?version=0.0.13 with the latest version of the compiler which right now is 3.1.27 and it still doesn't work. |
@qballer , I don't get it, the same Windows bug is still there. Please check the latest react-typescript compiler (3.1.27). |
Hey guys - react-typescript 3.1.28 should solve it (assuming the node_modules/ is the issue). @davidfirst I have no idea why it's not there. The fix is I believe to run tests on windows/mac as well. Lets discuss this off issue. if OP can confirm that it solves the issue it would be great. |
@qballer Just updated the component to work with 3.1.28. https://bit.dev/ofek/catdog/hook-test?version=0.0.14 Looks like it works, thanks! |
no problem. |
Description
I'm trying to make a simple bit component that uses React's hooks and Typescript. When I try to make one I get react's Invalid Hook Call Error (https://fb.me/react-invalid-hook-call) on the bit Overview page. I think this points to the error being more than one copy of react and tried to fix this by adding react as a peer dependency by adding this to my package.json:
This worked and changed react to a peer dependency, but I'm still getting the error. Here is component I'm working on: https://bit.dev/ofek/catdog/hook-test
I also tried making TS components without hooks and a JS components with hooks and both of those work fine.
Specifications
The text was updated successfully, but these errors were encountered: