UNPKG

@ledgerhq/live-common

Version:
21 lines 844 B
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