目前,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>
)
}
}
关于reactjs - 如何使用自定义主题提供程序包装 styleguidist 中的所有反应示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64018443/