|
14 | 14 | - [How to change style guide dev server logs output?](#how-to-change-style-guide-dev-server-logs-output)
|
15 | 15 | - [How to debug my components and examples?](#how-to-debug-my-components-and-examples)
|
16 | 16 | - [How to debug the exceptions thrown from my components?](#how-to-debug-the-exceptions-thrown-from-my-components)
|
| 17 | +- [How to use React's production or development build?](#how-to-use-reacts-production-or-development-build) |
17 | 18 | - [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)
|
18 | 19 | - [Why object references don’t work in example component state?](#why-object-references-dont-work-in-example-component-state)
|
19 | 20 | - [How to use Vagrant with Styleguidist?](#how-to-use-vagrant-with-styleguidist)
|
@@ -260,6 +261,33 @@ module.exports = {
|
260 | 261 | 2. Press the  button in your browser’s developer tools.
|
261 | 262 | 3. Press the  button and the debugger will stop execution at the next exception.
|
262 | 263 |
|
| 264 | +## How to use React's production or development build? |
| 265 | +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. |
| 266 | +```js |
| 267 | +import React from 'react'; |
| 268 | +import { TextInput } from 'react-native'; |
| 269 | + |
| 270 | +const CustomInput = ({value}) => <TextInput value={value} />; |
| 271 | + |
| 272 | +CustomInput.propTypes = { |
| 273 | + // will fail in a static build |
| 274 | + value: TextInput.value.isRequired, |
| 275 | +}; |
| 276 | +``` |
| 277 | +If you use code similar to this, you might encounter errors such as `Cannot read property 'isRequired' of undefined`. |
| 278 | + |
| 279 | +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. |
| 280 | + |
| 281 | +```json |
| 282 | +{ |
| 283 | + "scripts": { |
| 284 | + "build": "cross-env NODE_ENV=development react-styleguidist build" |
| 285 | + } |
| 286 | +} |
| 287 | +``` |
| 288 | +The script above uses [cross-env](https://github.com/kentcdodds/cross-env) to make sure the environment variable is properly set on all platforms. Run `npm i -D cross-env` to add it. |
| 289 | + |
| 290 | + |
263 | 291 | ## Why does the style guide list one of my prop types as `unknown`?
|
264 | 292 |
|
265 | 293 | This occurs when you are assigning props via `getDefaultProps` that are not listed within the components `propTypes`.
|
|
0 commit comments