reactjs - 如何使用自定义主题提供程序将所有反应示例包装在 styleguidist 中?
问题描述
目前,Styleguidist 使用 ReactExample 来渲染组件。我想用我的自定义主题提供程序将所有 ReactExample 组件包装在一个页面中。正如您在下面看到的,所有 ReactExample 组件都位于根 Styleguide 组件之外。
<StyleGuide />
<ReactExample />
<ReactExample />
<ReactExample />
有没有办法让我配置或修改 styleguidist 以添加一个父组件来包装 styleguidist 的所有组件?
<ThemeProvider>
<StyleGuide />
<ReactExample />
<ReactExample />
<ReactExample />
</ThemeProvider>
解决方案
您可以像这样包装所有组件:
在styleguide.config.js中:
const path = require('path')
module.exports = {
styleguideComponents: {
Wrapper: path.join(__dirname, 'src/styleguide/Wrapper')
}
}
组件/包装器:
import React, { Component } from 'react'
import { IntlProvider } from 'react-intl'
export default class Wrapper extends Component {
render() {
return (
<IntlProvider locale="en">{this.props.children}</IntlProvider>
)
}
}
推荐阅读
- asp.net - 从控制器添加或删除部分视图时的 asp.net core mvc
- sql - 在 SQL DB2 中,我如何解密可以是 YYYYMMDD 或 YYYYDDMM 的日期字符串
- c# - 为什么我在使用 MvxWpfSetup 时收到错误 CS0310
作为 RegisterSetupType - android - 将 vue web 应用程序转换为 ios 和 android 应用程序的最简单方法
- python - 使用图像创建新帖子的测试不起作用。姜戈
- javascript - 如何在使用 webpack for npm 创建包构建时添加 svg
- r - 如何使用 R 将每一行的数据帧转换为 json?
- python - Python pyodbc 查询一个字段不等于另一个字段
- java - 如何在 JCOP javacard shell 脚本中编写一个简单的 for 循环?
- pandas - 根据其中一列的条件制作数据框;需要知道正确的语法