小编Ped*_*ins的帖子

已发布的样式组件反应库无权访问用户应用程序 ThemeProvider

所以我正在为这家公司构建一个设计系统,并且组件系统在设计系统故事书中正确显示。但是当我将其导入消费者应用程序时,出现以下错误

TypeError: Cannot read property 'width' of undefined in theme.border.width
Run Code Online (Sandbox Code Playgroud)

设计系统项目:

/// src/components/Button/index.js
import { Wrapper } from './styles'
import React from 'react'

export const Button = (props) => (
  <Wrapper {...props}>
    {children}
  </Wrapper>
)
Run Code Online (Sandbox Code Playgroud)

///src/components/Button/styles.js    
export const Wrapper = styled.button`
...
border-width: ${({theme}) => theme.border.width};
...
`
Run Code Online (Sandbox Code Playgroud)

/// .storybook/preview.js
import React from 'react'
import { ThemeProvider } from 'styled-components'
import { GlobalStyle } from '../src/styles/globalStyles'
import { theme } from '../src/styles/theme'

export const parameters = {
  actions: …
Run Code Online (Sandbox Code Playgroud)

npm reactjs npm-publish styled-components next.js

2
推荐指数
1
解决办法
2493
查看次数

标签 统计

next.js ×1

npm ×1

npm-publish ×1

reactjs ×1

styled-components ×1