1.1.3 • Published 7 years ago

epic-component v1.1.3

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

Description

A simpler alternative writing style for React components:

Usage

EpicComponent(init) returns a React component that applies init to each element it creates.

Passing the element to init gives local functions defined in init painless access to the element.

The init function must set the render function on the element and may set the initial state.

init may also set any of the React lifecycle method: componentWillMount, componentDidMount, componentWillReceiveProps, componentWillUpdate, componentDidUpdate, componentWillUnmount.

PureComponent provides the default implementation of shouldComponentUpdate. The component may replace this implementation if necessary.

    import React from 'react';
    import EpicComponent from 'epic-component';
    
    export default EpicComponent(self => {

      // Set the initial state here.
      self.state = {value: 0};

      // Define callbacks as local functions capturing `self`.
      function onClick (event) {
        const newValue = self.state.value + 1;
        self.setState({value: newValue});
      };

      // Set the react render function.
      self.render = function () {
        // Refer to props as self.props.
        const className = self.props.className;
        const value = self.state.value;
        return (
          <p className={className} onClick={onClick}>Clicked {value} times</p>
        );
      };

    });
    
1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago