1.0.1 • Published 2 years ago

react-trace-update v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

react-trace-update

Tracing prop updates in a React component

License NPM Version Known Vulnerabilities NPM Downloads

Usage

useTraceUpdate

function MyComponent(props) {
    useTraceUpdate(props);
    return <div>Hello World!</div>;
}

Call the useTraceUpdate hook inside your functional component and pass in the props object.\ Whenever the component is re-rendered, the hook will log the changed props to the console.

withTraceUpdate

const WithTraceUpdate = withTraceUpdate(({ count }) => <div>{count}</div>, {
    onUpdate(props) {
        console.log("WithTraceUpdate props updated", props);
    },
});

withTraceUpdate allows you to wrap a component and automatically apply the useTraceUpdate hook to it.

Options

PropertyTyperequiredDescription
onUpdate(changedProps: Partial<Record<keyof T, any, any>>) => voidfalseA callback function that is called when props change. It receives the changed props as an argument.
1.0.1

2 years ago

1.0.0

2 years ago