Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add connecting components to Alt stores instructions via connectToStores #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions docs/connectToStores.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Connecting components to Alt stores

`connectToStores` wraps a React component and control its props with data coming from Alt stores.

Expects the Component to have two static methods:
- `getStores()`: Should return an array of stores.
- `getPropsFromStores(props)`: Should return the props from the stores.

## Usage Examples

### ES6 Class Higher Order Component
```js
import React from 'react';
import myStore from './stores/myStore';
import connectToStores from 'alt-utils/lib/connectToStores';

class MyComponent extends React.Component {
static getStores(props) {
return [myStore];
}

static getPropsFromStores(props) {
return myStore.getState();
}

render() {
// Use this.props like normal...
}
}

export default connectToStores(MyComponent);
```

### ES7 Decorator
```js
import React from 'react';
import myStore from './stores/myStore';
import connectToStores from 'alt-utils/lib/connectToStores';

@connectToStores
class MyComponent extends React.Component {
static getStores(props) {
return [myStore];
}

static getPropsFromStores(props) {
return myStore.getState();
}

render() {
// Use this.props like normal...
}
}
```