0.2.0 • Published 6 years ago

react-safe-clone v0.2.0

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

react-safe-clone

Declarative element cloning for React that doesn't overwrite props on child elements.

Usage

# Install with yarn or npm
yarn add react-safe-clone
import SafeClone from 'react-safe-clone';

class Interaction extends React.Component {
  handleOnClick = () => {
    // ...
  }

  render() {
    return (
      <SafeClone onClick={this.handleOnClick}>
        {this.props.children}
      </SafeClone>
    );
  }
}

const Button = ({ onClick, children }) => (
  <button onClick={onClick}>{children}</button>
);

// Potential usage in a component that has a `handleOnClick` method
// defined. Here, the `onClick` defined in `Interaction` will not overwrite
// the Button's `onClick` due to `SafeClone`.
<Interaction>
  <Button onClick={handleOnClick} />
</Interaction>
0.2.0

6 years ago

0.1.0

6 years ago