npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-container-helper

v0.3.3

Published

Help to generate react container component easily and functionally

Downloads

43

Readme

react-container-helper

npm Build Status Dependency Status Coverage Status

Help to generate react container component easily and functionally. Powered by Higher-Order Components.

Inspire by

Feature

  • [x] Use initState to set container's initial state
  • [x] Use mapSetStateToProps to map container's state, props or setState to component's properties
  • [x] Support container's life cycle method
  • [ ] Support purecomponent.

Full Example

You can see the simple example on example

import {contain} from 'react-container-helper';

const Button = ({ toggle, handleClick }) => (
  <button onClick={handleClick}>
    {toggle ? 'true' : 'false'}
  </button>
);

const initState = () => ({
  toggle: false,
});

const mapSetStateToProps = ({ toggle }, _, setState) => ({
  toggle,
  handleClick: () => setState({ toggle: !toggle }),
});

const ToggleButton = contain(initState, mapSetStateToProps)(Button);

ReactDOM.render(
  <ToggleButton />,
  document.getElementById('content')
);

Origin

import React from 'react';

const Button = ({toggle, handleClick}) => (
  <button onClick={handleClick}>
    {toggle ? "true" : "false"}
  </button>
);

class ToggleButton extends React.Component {

  constructor(props) {
    super(props);
    this.state = {toggle: false};

    this.handleClick = this.handleClick.bind(this);
  }

  handleClick() {
    this.setState({toggle: !this.state.toggle});
  }

  render() {
    return (
      <Button handleClick={this.handleClick} toggle={this.state.toggle}/>
    );
  }
}

ReactDOM.render(
  <ToggleButton />,
  document.getElementById('content')
);

API

contain(initState, mapSetStateToProps, setLifecycle)

Arguments

  • [initState(props)](Function): Use to set container initial state
  • [mapSetStateToProps(state, props, setState)](Function): Help to map container's state, props or setState to component's properties
  • [setLifecycle()](Function): Help to set container's lifecycle. Return the lifecycle object

Container's Lifecycle

Please use the setLifecycle to set and return the lifecycle object which define the lifecycle function.

  • [componentWillMount({ getState, getProps })](Function): Will be called on container will mount. getState and getProps can get the current container's value
  • [componentDidMount({ setState, getState, getProps })](Function): Will be called on container did mount. getState and getProps can get the current container's value. You can use setState to change the container's state
  • [componentWillReceiveProps(nextProps, { setState, getState, getProps })](Function): Will be called on container will receive properties. nextProps is the next properties. getState and getProps can get the current container's value. You can use setState to change the container's state
  • [shouldComponentUpdate(nextProps, nextState, { getState, getProps })](Function): Use to check container should update or not. nextProps and nextState is the next container's value. getState and getProps can get the current container's value.
  • [componentWillUpdate(nextProps, nextState, { getState, getProps })](Function): Will be called on container will update. nextProps and nextState is the next container's value. getState and getProps can get the current container's value.
  • [componentDidUpdate(prevProps, prevState, { setState, getState, getProps })](Function): Will be called on container did update. prevProps and prevState is the preview container's value. getState and getProps can get the current container's value. You can use setState to change the container's state
  • [componentWillUnmount({ getState, getProps })](Function): Will be called on container will unmount. getState and getProps can get the current container's value. Help you to clearup container.

Contribute

devDependency Status

  1. Fork it.
  2. Create your feature-branch git checkout -b your-new-feature-branch
  3. Commit your change git commit -am 'Add new feature'
  4. Push to the branch git push origin your-new-feature-branch
  5. Create new Pull Request with develop branch

License

The MIT License (MIT)

Copyright (c) 2016-2017 Lee < [email protected] >

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.