@@ -3,12 +3,44 @@ Debug utils for react components. Intended for development only, not for product
33
44## debug HOC
55
6- Lets you see in console when component mounts, unmounts, updates and why it updated
6+ Lets you see in console when component mounts, unmounts, updates and why it updated:
77
8- Basic usage:
98```
109import {debug} from "@morosystems/react-debug";
11- ...
10+
1211export default debug()(MyComponent);
1312```
14- Advanced usage: TODO
13+
14+ This logs roughly the following information:
15+ ```
16+ MyComponent mounts
17+ MyComponent updates name,input
18+ MyComponent updates error
19+ MyComponent unmounts
20+ ```
21+
22+ Displayed information can be changed using the configuration object, e.g.:
23+ ```
24+ export default debug({name: 'Test'})(MyComponent);
25+ ```
26+
27+ ### Component name
28+ You can specify name that is logged using the ` name ` property. You can specify:
29+ 1 . String.
30+ 2 . Function of props. This is useful when debugging one specific instance of generic component, e.g. ` Field ` .
31+
32+ ```
33+ export default debug({name: (props) => props.input.name})(Field);
34+ ```
35+ ### Custom logging
36+ You can also use custom messages for each lifecycle event.
37+ 1 . ` mount ` as a function from props to string.
38+ 2 . ` update ` as a function from props and next props to string.
39+ 3 . ` unmount ` as a function from props to string.
40+
41+ You can also supress loging by returning ` null ` , ` undefined ` or ` false ` :
42+ ```
43+ const update = (props, nextProps) => (props.name !== nextProps.name) && `${props.name} updates to ${nextProps.name}`;
44+
45+ export default debug({update})(MyComponent);
46+ ```
0 commit comments