File tree Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Expand file tree Collapse file tree 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.
6767🔥 useEffect (effect, [" hot" ]); // the simplest way to make hook reloadable
6868```
6969
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+
7075** To disable hooks reloading** - set configuration option:
7176
7277``` js
Original file line number Diff line number Diff line change @@ -11,9 +11,15 @@ const configuration = {
1111 // Allows SFC to be used, enables "intermediate" components used by Relay, should be disabled for Preact
1212 allowSFC : true ,
1313
14- // Allow hot reload of effect hooks
14+ // Allow reload of effect hooks with non zero dependency list
1515 reloadHooks : true ,
1616
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+
1723 // Disable "hot-replacement-render"
1824 disableHotRenderer : false ,
1925
Original file line number Diff line number Diff line change @@ -29,8 +29,24 @@ const forceSimpleSFC = { proxy: { pureSFC: true } };
2929
3030const hookWrapper = hook => {
3131 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 ) ;
3450 }
3551 return hook ( cb , deps ) ;
3652 } ;
You can’t perform that action at this time.
0 commit comments