反应无效挂钩调用错误和故事书 6
React invalid hook call error and storybook 6
我的所有挂钩都会导致无效挂钩调用错误,这是在使用 npx sb init
安装故事书后发生的
import React from 'react'
import { useSectionsQuery } from "../../graphql/generated";
export const Home: React.FC = () => {
const { data } = useSectionsQuery();
return (
<div className="bg-gray-200">
<div style={{ backgroundColor: "#4267B2" }} className="grid grid-rows-1">
<div className="flex justify-center">
{data?.sectionMany.map((section: any) => {
return <Card {...section} />;
})}
</div>
</div>
</div>
)
}
The solution for me:
- 我已经从 package.json;
中删除了所有 storybook 依赖项
- 我删除了 yarn.lock 文件和 node_modules 文件夹;
- 我已将 package.json 上的 React 和 react-dom 版本锁定为
16.13.1;
- 我已将以下决议添加到我的package.json:
"resolutions": {
"react": "^16.13.1",
"react-dom": "^16.13.1"
}
- 我已经从我的 workspaces.nohoist 中删除了 React 依赖项
package.json;
- 我使用 npx sb init 从零开始安装了 Storybook。
引自开发者
@eric-burel we're revamping a bunch of this stuff in 6.1, like #11628 and also removing the webpack DLLs which also cause lots of dependency sensitivity
阅读更多here
对于那些带着 NextJS v10 和 Storybook v6 来到这里的人:
Storybook 不支持 react v17,您可以通过 运行 检查不匹配的版本:
npm ls react-dom
和 npm ls react
.
Storybook 最近发布了修复此问题的测试版,您可以通过以下方式安装:
npx sb upgrade --prerelease
更多信息和对话在这里:https://github.com/storybookjs/storybook/issues/12408
我的所有挂钩都会导致无效挂钩调用错误,这是在使用 npx sb init
import React from 'react'
import { useSectionsQuery } from "../../graphql/generated";
export const Home: React.FC = () => {
const { data } = useSectionsQuery();
return (
<div className="bg-gray-200">
<div style={{ backgroundColor: "#4267B2" }} className="grid grid-rows-1">
<div className="flex justify-center">
{data?.sectionMany.map((section: any) => {
return <Card {...section} />;
})}
</div>
</div>
</div>
)
}
The solution for me:
- 我已经从 package.json; 中删除了所有 storybook 依赖项
- 我删除了 yarn.lock 文件和 node_modules 文件夹;
- 我已将 package.json 上的 React 和 react-dom 版本锁定为 16.13.1;
- 我已将以下决议添加到我的package.json:
"resolutions": {
"react": "^16.13.1",
"react-dom": "^16.13.1"
}
- 我已经从我的 workspaces.nohoist 中删除了 React 依赖项 package.json;
- 我使用 npx sb init 从零开始安装了 Storybook。
引自开发者
@eric-burel we're revamping a bunch of this stuff in 6.1, like #11628 and also removing the webpack DLLs which also cause lots of dependency sensitivity
阅读更多here
对于那些带着 NextJS v10 和 Storybook v6 来到这里的人:
Storybook 不支持 react v17,您可以通过 运行 检查不匹配的版本:
npm ls react-dom
和 npm ls react
.
Storybook 最近发布了修复此问题的测试版,您可以通过以下方式安装:
npx sb upgrade --prerelease
更多信息和对话在这里:https://github.com/storybookjs/storybook/issues/12408