我们不能直接向 App.js 注入组件吗?

Can't we inject component directly to App.js?

我是web新手development.After我学完了html,css和js(基本的东西)我最近开始学习react js。在我的第一个项目设置 src 文件夹中,我看到 index.js 和 app.js 文件。为什么我们这里需要 index.js 个文件?我们不能直接向 App.js 注入组件吗?

index一般用来表示交流_this是这个directory/hiearchy中的最高级别。 Index 是应用程序的入口点,它在 DOM 中被引导。 App 就像任何其他组件一样只是一个组件。您可以将其命名为任何名称,例如 RootComponentNotNamedApp

你不需要两者,但它保持索引文件干净,而无需添加一堆组件代码。在 App 中,您可能会用上下文、它们的提供者、添加其他组件等来包装事物。

我的应用程序使用 redux,所以索引中只有这个,

ReactDOM.render(
    // redux stuff
    <Provider store={store}>
        <App />
    </Provider>,
    document.getElementById('root')
)