为什么 Storybook 的数组旋钮在更改内容时不更新?
Why Storybook's array knob isn't updating when changing the content on it?
当我在控制台中看到它时,它确实更改了数组,但没有重新呈现它。所有其他旋钮都有效。我正在使用条件检查 body
是否有 length
足以渲染它。
故事:
import React from 'react'
import moment from 'moment'
import { storiesOf } from '@storybook/react'
import {
text,
boolean,
select,
number,
array,
date,
color as colorKnob
} from '@storybook/addon-knobs'
import Article from '@psl/ui/Article'
import ArticleReadMe from '@psl/ui/Article/README.md'
const defaultDate = new Date()
function formattedDateKnob(name, defaultValue) {
const stringTimestamp = date(name, defaultValue)
const currentDate = moment(stringTimestamp).format('dddd Do MMMM, YYYY')
return currentDate
}
const defaultBody = ['First paragraph', 'Second paragraph']
const articleStories = storiesOf('Articles', module)
articleStories
.addParameters({
readme: {
sidebar: ArticleReadMe
}
})
.add('Article', () => {
const isFetching = boolean('Is fetching?', false)
const title = text('Title of the article', 'Obesity in premature babies')
const articleDate = formattedDateKnob('Date', defaultDate)
const articleBody = array('Body of article', defaultBody)
const referenceLink = text('Reference link', 'https://link.com')
const reference = text(
'Reference',
'https://meetinglibrary.asco.org/record/185967/abstract'
)
const source = text('Source', 'University of Washington School of Medicine')
console.info(articleBody)
return (
<Article
isFetching={isFetching}
title={title}
date={articleDate}
body={defaultBody}
referenceLink={referenceLink}
reference={reference}
source={source}
/>
)
})
呈现该数组的部分组件:
{body.length &&
body.map((paragraph, index) => {
return (
<Typography type="body1" key={index} className={styles.body}>
<Markup html={paragraph} />
</Typography>
)
})}
这个应该
body={defaultBody}
是这个吗?
body={articleBody}
当我在控制台中看到它时,它确实更改了数组,但没有重新呈现它。所有其他旋钮都有效。我正在使用条件检查 body
是否有 length
足以渲染它。
故事:
import React from 'react'
import moment from 'moment'
import { storiesOf } from '@storybook/react'
import {
text,
boolean,
select,
number,
array,
date,
color as colorKnob
} from '@storybook/addon-knobs'
import Article from '@psl/ui/Article'
import ArticleReadMe from '@psl/ui/Article/README.md'
const defaultDate = new Date()
function formattedDateKnob(name, defaultValue) {
const stringTimestamp = date(name, defaultValue)
const currentDate = moment(stringTimestamp).format('dddd Do MMMM, YYYY')
return currentDate
}
const defaultBody = ['First paragraph', 'Second paragraph']
const articleStories = storiesOf('Articles', module)
articleStories
.addParameters({
readme: {
sidebar: ArticleReadMe
}
})
.add('Article', () => {
const isFetching = boolean('Is fetching?', false)
const title = text('Title of the article', 'Obesity in premature babies')
const articleDate = formattedDateKnob('Date', defaultDate)
const articleBody = array('Body of article', defaultBody)
const referenceLink = text('Reference link', 'https://link.com')
const reference = text(
'Reference',
'https://meetinglibrary.asco.org/record/185967/abstract'
)
const source = text('Source', 'University of Washington School of Medicine')
console.info(articleBody)
return (
<Article
isFetching={isFetching}
title={title}
date={articleDate}
body={defaultBody}
referenceLink={referenceLink}
reference={reference}
source={source}
/>
)
})
呈现该数组的部分组件:
{body.length &&
body.map((paragraph, index) => {
return (
<Typography type="body1" key={index} className={styles.body}>
<Markup html={paragraph} />
</Typography>
)
})}
这个应该
body={defaultBody}
是这个吗?
body={articleBody}