盖茨比组件阴影

Gatsby component shadowing

我正在使用 gatsby starter gatsby-theme-carbon. It has a switcher component whose code is available here。看起来像这样 Switcher screenshot.

如何使用组件阴影完全禁用切换器? (即我根本不想在我的网站上使用 Switcher)。

在此先感谢您的帮助。

如您在 Shadowing in Gatsby themes docs 中所见:

This feature allows users to replace a file in the src directory that is included in the webpack bundle with their own implementation. This works for React components, pages in src/pages, JSON files, TypeScript files, as well as any other imported file (such as .css) in your site.

阴影 API 使用确定性文件结构方法来了解应该或不应该呈现哪个组件。在您的情况下,您可以覆盖 CSS props 以将其显示为 none,或者您只是遮蔽和 return 一个空组件,因为遮蔽用于扩展 Gatsby主题。在您的项目中创建一个 src/gatsby-theme-blog/components/Switcher/Switcher.js 并执行如下操作:

const Switcher = () => {
  return <></>
};