Skip to content

Commit 45e0bab

Browse files
author
Artem Sapegin
committed
Docs: Add How to render React components that aren’t part of the style guide
styleguidist#970
1 parent a1fabe4 commit 45e0bab

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

docs/Cookbook.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* [How to use `ref`s in examples?](#how-to-use-refs-in-examples)
88
* [How to exclude some components from style guide?](#how-to-exclude-some-components-from-style-guide)
99
* [How to hide some components in style guide but make them available in examples?](#how-to-hide-some-components-in-style-guide-but-make-them-available-in-examples)
10+
* [How to render React components that aren’t part of the style guide?](#how-to-render-react-components-that-arent-part-of-the-style-guide)
1011
* [How to dynamically load other components in an example?](#how-to-dynamically-load-other-components-in-an-example)
1112
* [How to display the source code of any file?](#how-to-display-the-source-code-of-any-file)
1213
* [How to set global styles for user components?](#how-to-set-global-styles-for-user-components)
@@ -17,7 +18,7 @@
1718
* [How to change style guide dev server logs output?](#how-to-change-style-guide-dev-server-logs-output)
1819
* [How to debug my components and examples?](#how-to-debug-my-components-and-examples)
1920
* [How to debug the exceptions thrown from my components?](#how-to-debug-the-exceptions-thrown-from-my-components)
20-
* [How to use React's production or development build?](#how-to-use-reacts-production-or-development-build)
21+
* [How to use production or development build of React?](#how-to-use-production-or-development-build-of-react)
2122
* [Why does the style guide list one of my prop types as `unknown`?](#why-does-the-style-guide-list-one-of-my-prop-types-as-unknown)
2223
* [Why object references don’t work in example component state?](#why-object-references-dont-work-in-example-component-state)
2324
* [How to use Vagrant with Styleguidist?](#how-to-use-vagrant-with-styleguidist)
@@ -90,9 +91,18 @@ global.Button = Button
9091

9192
The `Button` component will be available in every example without a need to `require` it.
9293

94+
## How to render React components that aren’t part of the style guide?
95+
96+
Require these components in your examples:
97+
98+
```jsx noeditor
99+
const ColorPalette = require('./components/ColorPalette').default
100+
;<ColorPalette />
101+
```
102+
93103
## How to dynamically load other components in an example?
94104

95-
Although examples don't have direct access to webpack's `require.context` feature, you _can_ use it in a separate helper file which you require in your example code. If you wanted to create an example to load and show all of your icon components, you could do this:
105+
Although examples dont have direct access to webpacks `require.context` feature, you _can_ use it in a separate helper file which you require in your example code. If you wanted to create an example to load and show all of your icon components, you could do this:
96106

97107
```jsx
98108
// load-icons.js
@@ -122,7 +132,7 @@ const iconElements = Object.keys(icons).map(iconName => {
122132

123133
## How to display the source code of any file?
124134

125-
First, coode examples can receive [props and settings](Documenting.md#usage-examples-and-readme-files):
135+
First, code examples can receive [props and settings](Documenting.md#usage-examples-and-readme-files):
126136

127137
```js { "file": "../mySourceCode.js" }
128138
```
@@ -359,9 +369,9 @@ module.exports = {
359369
2. Press the ![Debugger](https://d3vv6lp55qjaqc.cloudfront.net/items/2h2q3N123N3G3R252o41/debugger.png) button in your browser’s developer tools.
360370
3. Press the ![Continue](https://d3vv6lp55qjaqc.cloudfront.net/items/3b3c1P3g3O1h3q111I2l/continue.png) button and the debugger will stop execution at the next exception.
361371

362-
## How to use React's production or development build?
372+
## How to use production or development build of React?
363373

364-
In some cases, you might need to use React's development build instead of the default [production one](https://reactjs.org/docs/optimizing-performance.html#use-the-production-build). For example, this might be needed if you use React Native and make references to a React Native component's propTypes in your code. As React removes all propTypes in its production build, your code will fail. By default, React Styleguidist uses the development build for the dev server, and the production one for static builds.
374+
In some cases, you might need to use development build of React instead of the default [production one](https://reactjs.org/docs/optimizing-performance.html#use-the-production-build). For example, this might be needed if you use React Native and make references to a React Native component's PropTypes in your code. As React removes all PropTypes in its production build, your code will fail. By default, React Styleguidist uses the development build for the dev server, and the production one for static builds.
365375

366376
```js
367377
import React from 'react'
@@ -377,7 +387,7 @@ CustomInput.propTypes = {
377387

378388
If you use code similar to this, you might encounter errors such as `Cannot read property 'isRequired' of undefined`.
379389

380-
To avoid this, you need to tell React Styleguidist to use React's development build. To do this, simply set the `NODE_ENV` variable to `development` in your npm script.
390+
To avoid this, you need to tell React Styleguidist to use Reacts development build. To do this, simply set the `NODE_ENV` variable to `development` in your npm script.
381391

382392
```json
383393
{

0 commit comments

Comments
 (0)