@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
21 lines • 844 B
JavaScript
import React, { useCallback, useState } from "react";
/**
* Use this to wrap your component and pass it a function "remountMe" as a prop
* that simply remounts the component.
* */
export default function withRemountableWrapper(Component) {
const WrappedComponent = (props) => {
const [nonce, setNonce] = useState(0);
const remountMe = useCallback(() => {
setNonce(nonce + 1);
}, [nonce, setNonce]);
/**
* The "key" prop identifies a unique instance of a component, so if it
* changes, the current instance is unmounted and a new instance is mounted
* with a new state.
* */
return React.createElement(Component, { key: nonce, ...props, remountMe: remountMe });
};
return WrappedComponent;
}
//# sourceMappingURL=withRemountableWrapper.js.map