如何在 Typescript Gatsby 中使用 ```gatsby-plugin-dark-mode```
How to use ```gatsby-plugin-dark-mode``` in Typescript Gatsby
我想达到的目标
在 Typescript Gatsby 中使用 'gatsby-plugin-dark-mode'
到目前为止我做了什么
- 安装 'gatsby-plugin-dark-mode'
yarn add gatsby-plugin-dark-mode
- 在 gatsby-config.js
中包含 'gatsby-plugin-dark-mode'
module.exports = {
plugins: ['gatsby-plugin-dark-mode'],
}
- 定义 ThemeToggler 组件并导入 'gatsby-plugin-dark-mode'
import React from 'react'
import { ThemeToggler } from 'gatsby-plugin-dark-mode'
class MyComponent extends React.Component {
render() {
return (
<ThemeToggler>
{({ theme, toggleTheme }) => (
<label>
<input
type="checkbox"
onChange={e => toggleTheme(e.target.checked ? 'dark' : 'light')}
checked={theme === 'dark'}
/>{' '}
Dark mode
</label>
)}
</ThemeToggler>
)
}
}
那么...
Could not find a declaration file for module 'gatsby-plugin-dark-mode'. '/Desktop/my-blog/gatsby-casper/node_modules/gatsby-plugin-dark-mode/index.js' implicitly has an 'any' type.
我想咨询和帮助的问题
- 我是不是忽略了什么??
- Tyepscript Gatsby 不支持 'gatsby-plugin-dark-mode' 吗??
- 如果可以将 'gatsby-plugin-dark-mode' 与 Tyepscript Gatsby 一起使用,请告诉我这里缺少的内容。
如果您还没有,请在项目的根目录中创建一个名为 global.d.ts
的全局接口文件,然后添加:
declare module 'gatsby-plugin-dark-mode';
您可以将此代码段用于任何抛出该错误且没有已发布类型的包。
我想达到的目标
在 Typescript Gatsby 中使用 'gatsby-plugin-dark-mode'
到目前为止我做了什么
- 安装 'gatsby-plugin-dark-mode'
yarn add gatsby-plugin-dark-mode
- 在 gatsby-config.js 中包含 'gatsby-plugin-dark-mode'
module.exports = {
plugins: ['gatsby-plugin-dark-mode'],
}
- 定义 ThemeToggler 组件并导入 'gatsby-plugin-dark-mode'
import React from 'react'
import { ThemeToggler } from 'gatsby-plugin-dark-mode'
class MyComponent extends React.Component {
render() {
return (
<ThemeToggler>
{({ theme, toggleTheme }) => (
<label>
<input
type="checkbox"
onChange={e => toggleTheme(e.target.checked ? 'dark' : 'light')}
checked={theme === 'dark'}
/>{' '}
Dark mode
</label>
)}
</ThemeToggler>
)
}
}
那么...
Could not find a declaration file for module 'gatsby-plugin-dark-mode'. '/Desktop/my-blog/gatsby-casper/node_modules/gatsby-plugin-dark-mode/index.js' implicitly has an 'any' type.
我想咨询和帮助的问题
- 我是不是忽略了什么??
- Tyepscript Gatsby 不支持 'gatsby-plugin-dark-mode' 吗??
- 如果可以将 'gatsby-plugin-dark-mode' 与 Tyepscript Gatsby 一起使用,请告诉我这里缺少的内容。
如果您还没有,请在项目的根目录中创建一个名为 global.d.ts
的全局接口文件,然后添加:
declare module 'gatsby-plugin-dark-mode';
您可以将此代码段用于任何抛出该错误且没有已发布类型的包。