Have ideas to improve npm?Join in the discussion! »

    react-remount

    1.0.2 • Public • Published

    react-remount

    A simple component that injects a pre-defined prop as a key to the wrapped component, thus ensuring a re-mounting (a state reset) each time this prop is changed

    NPM JavaScript Style Guide

    Install

    npm install --save react-remount

    Usage

    import React, { Component } from 'react';
    import withRemount from 'react-remount';
     
    class MyLib extends Component {
      render () {
        const {firstName, lastName} = this.props
        return (
          <div>{`Hello ${firstName} ${lastName}`}</div>
        )
      }
    }
     
    MyLib = withRemount(MyLib, 'firstName');
    export default MyLib;

    Now when ever we use MyLib, react-remount will inject the value of firstName as a key.

    <MyLib firstName="John" lastName="Doe>
    

    We can also pass a function to withRemount, as long as this function returns a string.
    This is helpful when you want to chain multiple props as your key:

    MyLib = withRemount(MyLib, props => props.firstName + props.lastName);
    

    License

    MIT © sag1v

    Install

    npm i react-remount

    DownloadsWeekly Downloads

    133

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    92.2 kB

    Total Files

    6

    Last publish

    Collaborators

    • avatar