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
Install
npm install --save react-remount
Usage
import React Component from 'react';import withRemount from 'react-remount'; { const firstName lastName = thisprops return <div>`Hello `</div> } MyLib = ;;
MyLib
, react-remount
will inject the value of firstName
as a key.
Now when ever we use <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