Storybook: λ°˜μ‘ λΌμš°ν„°κ°€ μžˆλŠ” ꡬ성 μš”μ†Œ

에 λ§Œλ“  2017λ…„ 04μ›” 14일  Β·  13μ½”λ©˜νŠΈ  Β·  좜처: storybookjs/storybook

λ°˜μ‘ λΌμš°ν„°λ₯Ό μ‚¬μš©ν•˜λŠ” ꡬ성 μš”μ†Œμ™€ ν•¨κ»˜ μŠ€ν† λ¦¬λΆμ„ μ‚¬μš©ν•˜λŠ” 방법

ꡬ성 μš”μ†Œ 예

import React from 'react'
import PropTypes from 'prop-types'
import { Link } from 'react-router-dom'
import Brand from './components'

const Logo = ({children}) => {
  return (
    <Link to='/'>
      <Brand>
        {children}
      </Brand>
    </Link>
  )
}

Logo.propTypes = {
  children: PropTypes.string.isRequired
}

export default Logo

였λ₯˜

screen shot 2017-04-14 at 4 27 22 am

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

addDecorator ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•˜μ—¬ μŠ€ν† λ¦¬λ₯Ό MemoryRouter 감싸야 ν•©λ‹ˆλ‹€. λ‹€μŒμ€ μŠ€λ‹ˆνŽ«μž…λ‹ˆλ‹€.

storiesOf('Logo', module)
  .addDecorator(story => (
      <MemoryRouter initialEntries={['/']}>{story()}</MemoryRouter>
  ))
  .add('normal', () => <Logo />)

μ—¬κΈ°μ—μ„œ 전체 예제λ₯Ό 읽을 수 μžˆμŠ΅λ‹ˆλ‹€: https://blog.hichroma.com/graphql-react-tutorial-part-5-6-ac36b6962a8a

λͺ¨λ“  13 λŒ“κΈ€

addDecorator ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•˜μ—¬ μŠ€ν† λ¦¬λ₯Ό MemoryRouter 감싸야 ν•©λ‹ˆλ‹€. λ‹€μŒμ€ μŠ€λ‹ˆνŽ«μž…λ‹ˆλ‹€.

storiesOf('Logo', module)
  .addDecorator(story => (
      <MemoryRouter initialEntries={['/']}>{story()}</MemoryRouter>
  ))
  .add('normal', () => <Logo />)

μ—¬κΈ°μ—μ„œ 전체 예제λ₯Ό 읽을 수 μžˆμŠ΅λ‹ˆλ‹€: https://blog.hichroma.com/graphql-react-tutorial-part-5-6-ac36b6962a8a

μŠ€ν† λ¦¬λΆ μž‘μ—…μ„ μ‹€ν–‰ν•˜λŠ” 링크λ₯Ό μ›ν•˜λ©΄ μ—¬κΈ°μ—μ„œ 이 λŒ“κΈ€μ„ μ°Έμ‘°ν•˜μ„Έμš”. https://github.com/storybooks/react-storybook/issues/485#issuecomment -294105214

이 였λ₯˜λ₯Ό μ°Ύκ³  μžˆμ—ˆλŠ”λ° 이미지에 κ²Œμ‹œλ˜μ–΄ 있기 λ•Œλ¬Έμ— 이 문제λ₯Ό μ°ΎλŠ” 데 어렀움을 κ²ͺμ—ˆμŠ΅λ‹ˆλ‹€. μ‚¬λžŒλ“€μ΄ μ•žμœΌλ‘œ 더 μ‰½κ²Œ 찾을 수 μžˆλ„λ‘ μ§€κΈˆ ν…μŠ€νŠΈλ₯Ό λΆ™μ—¬λ„£μœΌμ„Έμš”.

μ •μ˜λ˜μ§€ μ•Šμ€ 속성 '기둝'을 읽을 수 μ—†μŠ΅λ‹ˆλ‹€.
TypeError: μ •μ˜λ˜μ§€ μ•Šμ€ '기둝' 속성을 읽을 수 μ—†μŠ΅λ‹ˆλ‹€.
Link.renderμ—μ„œ (http://localhost:9001/static/preview.bundle.js:52878:35)
http://localhost :9001/static/preview.bundle.js:43410:21μ—μ„œ
measureLifeCyclePerfμ—μ„œ (http://localhost:9001/static/preview.bundle.js:42690:12)
ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (http://localhost:9001/static/preview.bundle.js:43409:25)
ReactCompositeComponentWrapper._renderValidatedComponent (http://localhost:9001/static/preview.bundle.js:43436:32)
ReactCompositeComponentWrapper.performInitialMount (http://localhost:9001/static/preview.bundle.js:42976:30)
ReactCompositeComponentWrapper.mountComponent (http://localhost:9001/static/preview.bundle.js:42872:21)
Object.mountComponentμ—μ„œ (http://localhost:9001/static/preview.bundle.js:4438:35)
ReactDOMComponent.mountChildrenμ—μ„œ (http://localhost:9001/static/preview.bundle.js:42241:44)
ReactDOMComponent._createInitialChildrenμ—μ„œ (http://localhost:9001/static/preview.bundle.js:40403:32)

MemoryRouter λ₯Ό μ‚¬μš©ν•˜λŠ” λ™μ•ˆ μ•„λž˜ 였λ₯˜κ°€ λ°œμƒν•˜κ³  MemoryRouter κ°€ undefined 둜 λ‚˜μ˜€λŠ” 것 κ°™μŠ΅λ‹ˆλ‹€.

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.
    at invariant (http://localhost:6006/static/preview.bundle.js:2056:15)
    at createFiberFromElementType (http://localhost:6006/static/preview.bundle.js:27773:5)
    at createFiberFromElement (http://localhost:6006/static/preview.bundle.js:27718:15)
    at reconcileSingleElement (http://localhost:6006/static/preview.bundle.js:28966:19)
    at reconcileChildFibers (http://localhost:6006/static/preview.bundle.js:29065:35)
    at reconcileChildrenAtPriority (http://localhost:6006/static/preview.bundle.js:29715:30)
    at reconcileChildren (http://localhost:6006/static/preview.bundle.js:29706:5)
    at finishClassComponent (http://localhost:6006/static/preview.bundle.js:29842:5)
    at updateClassComponent (http://localhost:6006/static/preview.bundle.js:29814:12)
    at beginWork (http://localhost:6006/static/preview.bundle.js:30193:16)

무슨 일이 μΌμ–΄λ‚˜κ³  μžˆλŠ”μ§€ μ–΄λ–€ 아이디어가 μžˆμŠ΅λ‹ˆκΉŒ?

μ•ˆλ…•ν•˜μ„Έμš” @oyeanuj ,
이것에 λŒ€ν•œ μ†Œμ‹μ΄ μžˆμŠ΅λ‹ˆκΉŒ? Route μ‚¬μš©ν•  λ•Œ κ½€ λΉ„μŠ·ν•œ λ¬Έμ œκ°€ λ°œμƒν•©λ‹ˆλ‹€.

@aperkaz 아직 μž‘λ™ν•˜μ§€ μ•Šμ•„μ„œ Storybook에 ν•΄λ‹Ή ꡬ성 μš”μ†Œλ₯Ό ν¬ν•¨ν•˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.

μ‚¬μš© 쀑인 λ°˜μ‘ λΌμš°ν„°μ˜ 버전을 ν™•μΈν•˜κ³  싢을 수 μžˆμŠ΅λ‹ˆλ‹€.

μœ„μ˜ @shilman 의 μ†”λ£¨μ…˜μ€ λ°˜μ‘ λΌμš°ν„° 4.1.1 및 @storybook/react v 3.3.8μ—μ„œ μž‘λ™ν•©λ‹ˆλ‹€.

λ°˜μ‘ λΌμš°ν„° 3의 경우:

// ...
import { Router, Route } from 'react-router';
import createMemoryHistory from 'react-router/lib/createMemoryHistory';

storiesOf('Foo', module)
  .addDecorator(story => (
    <Router history={createMemoryHistory('/')}>
      <Route path="/" component={() => story()} />
    </Router>
  ))
  .add('Default', () => <Foo />);

수락 된 닡변은 ν›Œλ₯­ν•˜κ²Œ μž‘λ™ν•˜μ§€λ§Œ

Uncaught ReferenceError: ___loader is not defined

이 였λ₯˜μ— λŒ€ν•œ 도움

인터넷 검색을 ν•˜κ³  머리카락을 λœ―μ€ 후에 여기에 μ˜€λŠ” μ‚¬λžŒμ„ μœ„ν•΄ μ‹œκ°„μ„ μ ˆμ•½ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

λ‚΄κ°€ μž‘μ—…ν•˜κ³  있던 ν”„λ‘œμ νŠΈλŠ” react-router (package.json의 "^4.1.1"에 있음)와 react-router-dom ("next"에 있음) 사이에 버전 λΆˆμΌμΉ˜κ°€ μžˆμ—ˆμŠ΅λ‹ˆλ‹€.

이것은 Reactκ°€ this.context μž‘λ™ 방식을 λ³€κ²½ν•˜κ³  react-router-dom λ‹€μŒ μ†Œμ†‘μœΌλ‘œ 인해 제 κ²½μš°μ— 문제λ₯Ό μΌμœΌμΌ°μŠ΅λ‹ˆλ‹€. 이것은 λ‚΄ <Link /> κ°€ 아직 μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” λ°©λ²•μœΌλ‘œ μ»¨ν…μŠ€νŠΈλ₯Ό κ°€μ Έμ˜€λ €κ³  ν•˜κ³  맀우 도움이 λ˜μ§€ μ•ŠλŠ” "당신은 μ‚¬μš©ν•΄μ„œλŠ” μ•ˆ λ©λ‹ˆλ‹€. μ™ΈλΆ€" 였λ₯˜.

"react-router-dom": "^4.1.1" "react-router-dom": "next" 둜 μ „ν™˜ν•˜μ—¬ 문제λ₯Ό ν•΄κ²°ν–ˆμŠ΅λ‹ˆλ‹€.

λ‹€λ₯Έ μ‚¬λžŒμ—κ²Œ μ‹€μ œλ‘œ 도움이 된 것은 이 νŒ¨ν‚€μ§€μ˜€μŠ΅λ‹ˆλ‹€. https://github.com/gvaldambrini/storybook-router/

λ‹΅λ³€ κ°μ‚¬ν•©λ‹ˆλ‹€ 도움이 λ˜μ—ˆμŠ΅λ‹ˆλ‹€

후크λ₯Ό μ‚¬μš©ν•˜λŠ” μ‚¬λžŒμ˜ 경우:

```
'기둝'μ—μ„œ { createMemoryHistory } κ°€μ Έμ˜€κΈ°
'react-router-dom'μ—μ„œ { λΌμš°ν„°, 경둜 } κ°€μ Έμ˜€κΈ°

const 기둝 = createMemoryHistory({ initialEntries: ['/'] })

addDecorator(μŠ€ν† λ¦¬ =>)

addDecorator(μŠ€ν† λ¦¬ => (


))
``

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰