Skip to content

Add docs about using require() in examples. #40

@mik01aj

Description

@mik01aj

#25 was merged, but I forgot to add the related documentation. TODO :)

Draft:


Writing usage examples

The examples are extracted from markdown code blocks. They can use any components defined on the page (all the components are exposed as global variables) without requiring them. If you need anything else, you can require it just like you would in an ordinary .js file. Here's a markdown example:

Simple example:

    <Message data={ {content: 'Hello world'} } />

More complex example:

    var mockData = require('./mocks');
    <Message data={ {content: 'Hello world'} } />

Note that for mock data, it's often a good idea to use the same mocks in the unit tests too.

If you need more complex demos, you can even use React.createClass right in your code examples, but it's often a good idea to define them in a separate MyComponentDemo.js file instead and then just require them in markdown.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions