diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-12-22 10:18:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-22 10:18:38 +0100 |
commit | 194ebc3da9641ff96f083f9d8ab43c2d27944f9a (patch) | |
tree | c50988f32ccf18df93ae7ab40be78e9459642818 /docs/api/connect.md | |
parent | 64ccb6b00b4b63fa0e516d4e35351275b34f8c07 (diff) | |
parent | 16af264360e48e8a833e9efa9ab8d194574dbc70 (diff) | |
download | gitbook-194ebc3da9641ff96f083f9d8ab43c2d27944f9a.zip gitbook-194ebc3da9641ff96f083f9d8ab43c2d27944f9a.tar.gz gitbook-194ebc3da9641ff96f083f9d8ab43c2d27944f9a.tar.bz2 |
Merge pull request #1543 from GitbookIO/dream
React for rendering website with plugins
Diffstat (limited to 'docs/api/connect.md')
-rw-r--r-- | docs/api/connect.md | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/docs/api/connect.md b/docs/api/connect.md new file mode 100644 index 0000000..740deca --- /dev/null +++ b/docs/api/connect.md @@ -0,0 +1,33 @@ +# Connect to the context + +`GitBook.connect(Component, [mapStateToProps], [mapActionsToProps])` connects a react component to the GitBook context. + +It does not modify the component class passed to it. +Instead, it returns a new, connected component class, for you to use. + +### `mapStateToProps(state, [ownProps]): stateProps` + +If specified, the component will subscribe to GitBook store updates. Any time it updates, `mapStateToProps` will be called. Its result must be a plain object, and it will be merged into the component’s props. + +If you omit it, the component will not be subscribed to the GitBook store. If `ownProps` is specified as a second argument, its value will be the props passed to your component, and `mapStateToProps` will be additionally re-invoked whenever the component receives new props (e.g. if props received from a parent component have shallowly changed, and you use the `ownProps` argument, `mapStateToProps` is re-evaluated). + +For example to render the title of the current page: + +```js +const GitBook = require('gitbook-core'); + +let PageTitle = React.createClass({ + render() { + const { page } = this.props; + return <h1>{page.title}</h1>; + } +}); + +function mapStateToProps(state) { + return { page: state.page }; +} + +PageTitle = GitBook.connect(PageTitle, mapStateToProps); +``` + +### `mapActionsToProps(actions, [dispatch])` |