0.1.0 • Published 7 years ago

react-container-as-prop v0.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

react-container-as-prop

Attach React Container as a prop to Component

Installation

npm

npm install react-container-as-prop --save

yarn

yarn add react-container-as-prop

PlayGround

App.js

import React from "react";

export default class App extends React.Component {
  render() {
    return (
      <div>
        <PersonName container={PersonData} />
        <PersonNameReversed container={PersonData} />
        <Country container={CountryData} />
      </div>
    );
  }
}

PersonData.js

import { BaseContainer } from "react-container-as-prop";

export default class PersonData extends BaseContainer {
  getData() {
    return { firstName: "Bhagat", lastName: "Singh" };
  }
}

PersonName.js

import React from "react";
import { BaseComponent } from "react-container-as-prop";

export default class PersonName extends BaseComponent {
  render() {
    const { firstName, lastName } = this.props;

    return (
      <div>
        <div>
          {firstName} {lastName}
        </div>
      </div>
    );
  }
}

PersonNameReversed.js

import React from "react";
import { BaseComponent } from "react-container-as-prop";

export default class PersonNameReversed extends BaseComponent {
  render() {
    const { firstName, lastName } = this.props;

    return (
      <div>
        <div>
          {lastName}, {firstName}
        </div>
      </div>
    );
  }
}

Development

To run the demo locally

git clone git@github.com:souvikbasu/react-container-as-prop.git
cd react-container-as-prop/demo
yarn
yarn start
open http://localhost:3000
0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago