16.12.3 • Published 6 years ago

alt-store-connect v16.12.3

Weekly downloads
113
License
MIT
Repository
-
Last release
6 years ago

Connecting components to Alt stores

Install

npm install alt-store-connect --save

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

This module supports React 16

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

import React from 'react';
import myStore from './stores/myStore';
import connectToStores from 'alt-connect-store';

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

import React, { Component } from 'react'
import myStore from './stores/myStore'
import connectToStores from 'alt-connect-store'

@connectToStores
export default class MyComponent extends Component {

    static getStores(props) {
        return [myStore]
    }

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

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

6 years ago

16.12.2

6 years ago

16.12.1

6 years ago

16.12.0

6 years ago

16.3.0

7 years ago

16.0.1

8 years ago

16.0.0

8 years ago

0.16.6

8 years ago

0.16.5

8 years ago

0.16.3

8 years ago

0.16.2

8 years ago

0.16.1

8 years ago

0.16.0

8 years ago