0.1.1 • Published 9 years ago

react-subcomponent v0.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

react-subcomponent

A stateless react component

Usage

Parent that holds state:

import React from 'react';
import Child from './child.js';

class Parent extends React.Component {

    constructor(props){
        super();

        this.state = {
            // some state
        }
    }
    render() {
        return (
            <Child parent={this}/>
        );
    }
}

Child that has no state but can access and set its parents state:

import React from 'react';
import SubComponent from 'react-subcomponent';

class Child extends SubComponent {

    handleClick(){
        this.setState({}) // sets parents state
    }

    render() {
        return (
            <div onClick={this.handleClick.bind(this)}>
                {this.state} // gets parents state
            </div>
        );
    }
}