λ°μ λΌμ°ν°λ₯Ό μ¬μ©νλ κ΅¬μ± μμμ ν¨κ» μ€ν 리λΆμ μ¬μ©νλ λ°©λ²
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
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(μ€ν 리 => (
))
``
κ°μ₯ μ μ©ν λκΈ
addDecorator
ν¨μλ₯Ό μ¬μ©νμ¬ μ€ν 리λ₯ΌMemoryRouter
κ°μΈμΌ ν©λλ€. λ€μμ μ€λν«μ λλ€.μ¬κΈ°μμ μ 체 μμ λ₯Ό μ½μ μ μμ΅λλ€: https://blog.hichroma.com/graphql-react-tutorial-part-5-6-ac36b6962a8a