🚨 Latest Research:Tanstack npm Packages Compromised in Ongoing Mini Shai-Hulud Supply-Chain Attack.Learn More →
Socket
Book a DemoSign in
Socket

material-flux-container

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

material-flux-container

provice container utils for material-flux

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

material-flux-container

Provide Container Component for material-flux.

Installation

npm install material-flux-container

Dependencies

  • material-flux
  • React

Usage

Container has same API to Flux Utils.

Container.create(base: ReactClass): ReactClass

Create is used to transform a react class into a container that updates its state when relevant stores change. The provided base class must have static methods getStores() and calculateState().

Example

See example/

import React from 'react';
import {render} from "react-dom";
import Container from "material-flux-container";
import UserContext from './UserContext.js';
const context = new UserContext();
export default class App extends React.Component {
    constructor(...args) {
        super(...args);
        this.userStore = context.userStore;
        this.state = {
            userData: this.userStore.getUserData()
        };
    }
    // Container require #getStores
    static getStores() {
        return [context.userStore]
    }
    // Container require #calculateState
    static calculateState(prevState) {
        return {
            userData: context.userStore.getUserData()
        }
    }

    onClick(event) {
        context.userAction.doSomething("clicked");
    }

    render() {
        return (
            <button onClick={this.onClick.bind(this)}>
                userData: {this.state.userData}
            </button>
        );
    }
}
// create container with `getStores` and `calculateState`
const container = Container.create(App);
render(
    React.createElement(container),
    document.getElementById("js-app")
);

Contributing

  • Fork it!
  • Create your feature branch: git checkout -b my-new-feature
  • Commit your changes: git commit -am 'Add some feature'
  • Push to the branch: git push origin my-new-feature
  • Submit a pull request :D

License

MIT

Keywords

flux

FAQs

Package last updated on 28 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts