React Component 与 SubComponent - 热重载不起作用
我的项目有一个简单的 SubComponent
问题。如果我在该 SubComonent
内进行任何更改,它不会热重新加载。我不知道如何解决它。
我的组件定义如下:
// Component.tsx
export const Component = () => {
return <div>Component</div>;
};
Component.SubComponent = function SubComponent() {
return <div>Hello From Sub</div>;
};
export const SubComponent1 = function SubComponent1() {
return <div>Hello From Sub1</div>;
};
用法:
// App.tsx
<Component.SubComponent />
<SubComponent1 />
如果我在 Component.SubComponent
中进行更改,它不会重新加载,但如果我在 SubComponent1
中进行更改,它效果很好。
我已经使用干净的 create-react-app 安装对此进行了测试,但它在那里也不起作用。
关于如何解决这个问题或代码有什么问题有什么想法吗?我在网上找到了很多关于子组件的文章。
I have an issue with my project with a simple SubComponent
. If I do any changes inside that SubComonent
it is not hot reloaded. I am not sure how to fix it.
I have components defined like this:
// Component.tsx
export const Component = () => {
return <div>Component</div>;
};
Component.SubComponent = function SubComponent() {
return <div>Hello From Sub</div>;
};
export const SubComponent1 = function SubComponent1() {
return <div>Hello From Sub1</div>;
};
And usage:
// App.tsx
<Component.SubComponent />
<SubComponent1 />
If I do changes in Component.SubComponent
it is not reloaded, but if I do changes in SubComponent1
it works well.
I have tested this with the clean create-react-app install and it does not work there too.
Any ideas on how to fix this or what is wrong with the code? I found quite a lot of articles about sub components on the internet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这种方法对我来说似乎很糟糕。
将组件一一导出。
我发现
很难看。另一种方法是:The approach seems bad to me.
Export components one by one.
I see that
<Form.Form />
is ugly. Another way would be: