File tree 3 files changed +30
-3
lines changed
3 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,11 @@ There is only one condition for it - a non zero dependencies list.
67
67
🔥 useEffect (effect, [" hot" ]); // the simplest way to make hook reloadable
68
68
```
69
69
70
+ ** Plus**
71
+
72
+ * any hook would be reloaded on a function body change. Enabled by default, controlled by ` reloadHooksOnBodyChange ` option.
73
+ * you may configure RHL to reload any hook by setting ` reloadLifeCycleHooks ` option to true.
74
+
70
75
** To disable hooks reloading** - set configuration option:
71
76
72
77
``` js
Original file line number Diff line number Diff line change @@ -11,9 +11,15 @@ const configuration = {
11
11
// Allows SFC to be used, enables "intermediate" components used by Relay, should be disabled for Preact
12
12
allowSFC : true ,
13
13
14
- // Allow hot reload of effect hooks
14
+ // Allow reload of effect hooks with non zero dependency list
15
15
reloadHooks : true ,
16
16
17
+ // Allow reload of mount effect hooks - zero deps
18
+ reloadLifeCycleHooks : false ,
19
+
20
+ // Enables hook reload on hook body change
21
+ reloadHooksOnBodyChange : true ,
22
+
17
23
// Disable "hot-replacement-render"
18
24
disableHotRenderer : false ,
19
25
Original file line number Diff line number Diff line change @@ -29,8 +29,24 @@ const forceSimpleSFC = { proxy: { pureSFC: true } };
29
29
30
30
const hookWrapper = hook => {
31
31
const wrappedHook = function ( cb , deps ) {
32
- if ( configuration . reloadHooks ) {
33
- return hook ( cb , deps && deps . length > 0 ? [ ...deps , getHotGeneration ( ) ] : deps ) ;
32
+ if ( configuration . reloadHooks && deps ) {
33
+ const inputs = [ ...deps ] ;
34
+
35
+ // reload hooks which have changed string representation
36
+ if ( configuration . reloadHooksOnBodyChange ) {
37
+ inputs . push ( String ( cb ) ) ;
38
+ }
39
+
40
+ if (
41
+ // reload hooks with dependencies
42
+ deps . length > 0 ||
43
+ // reload all hooks of option is set
44
+ ( configuration . reloadLifeCycleHooks && deps . length === 0 )
45
+ ) {
46
+ inputs . push ( getHotGeneration ( ) ) ;
47
+ }
48
+
49
+ return hook ( cb , inputs ) ;
34
50
}
35
51
return hook ( cb , deps ) ;
36
52
} ;
You can’t perform that action at this time.
0 commit comments