Closed julia-dizhak closed 3 years ago
Thanks for the feedback.
I suspect that your package manager installed both React 18 and 17. Multiple React versions is one of the reasons for the "invalid hook call" error message.
This might be due to dependencies requiring React 17 via peer dependencies.
What package manager are you using?
Hi @julia-dizhak :wave:
Can you help us by providing a link to a CodeSandbox (https://codesandbox.io/s/new), a repository on GitHub, or a minimal code example that reproduces the problem? The info provided isn't sufficient to rule out something like what @eps1lon mentions above.
hi @bvaughn thanks for taking care here is the sandbox https://codesandbox.io/s/b52q1
Thanks for the feedback.
I suspect that your package manager installed both React 18 and 17. Multiple React versions is one of the reasons for the "invalid hook call" error message.
This might be due to dependencies requiring React 17 via peer dependencies.
What package manager are you using?
hi @eps1lon thanks for support
I installed react alpha via yarn add react@alpha react-dom@alpha
, node is V14.16.1
As well I deleted node-modules and re-installed peer dependencies
Thanks for the repro!
hi @bvaughn thanks for taking care here is the sandbox codesandbox.io/s/b52q1
That looks like it's caused by a dev-only logic from styled-components (https://github.com/styled-components/styled-components/issues/3394, https://github.com/styled-components/styled-components/issues/3409) since the reported issue is already reproducible with
import styled from "styled-components";
const StyledPeopleIcon = styled("svg")`
margin: 10px;
`;
Closing since it's caused by a 3rd party library. The issue is already fixed in https://github.com/styled-components/styled-components/pull/3521 but not released yet.
Hmm, wait, something isn't right here.
The comments in https://github.com/styled-components/styled-components/pull/3521 claim:
// If a hook is called outside of a component:
// React 17 and earlier throw an error
// React 18 and above use console.error
I don't remember a change like this. I expect we still have a production invariant/error in cases of invalid Hook call.
Can we investigate what the difference is?
We throw here:
There is a DEV-only console.error here:
But it's supposed to throw right afterwards with null access (essentially, null.useState
).
Are you saying it doesn't throw anymore?
I don't remember a change like this. I expect we still have a production invariant/error in cases of invalid Hook call.
I'm pretty sure this was changed in https://github.com/facebook/react/pull/20604 since I saw the errors shortly after in integration tests with react@next
.
Are you saying it doesn't throw anymore?
It does throw but it's no longer clear why without also listening to the console. So the claim is a bit incomplete but sufficient for what we're trying to do: Checking if we're called from inside a function component requires different implementations for React 17 and 18 due to https://github.com/facebook/react/pull/20604
Ah ok.
I have a problem with rendering app after migrating to 18 version
I have Invalid hook call warning in console
node is V14.16.1 installed react alpha viayarn add react@alpha react-dom@alpha
Dependencies