@@ -35,7 +35,7 @@ class Foo extends React.Component {
35
35
}
36
36
37
37
getData () {
38
- // Return a promise or a sync value
38
+ // Return a promise or a sync value
39
39
return Promise .resolve (this .props .value );
40
40
}
41
41
@@ -66,10 +66,10 @@ const values = [];
66
66
* @param instance - If the current element is a Component or PureComponent
67
67
* then this will hold the reference to the created
68
68
* instance. For any other element type this will be null.
69
- * @param context - The current "React Context". Any provided childContexTypes
69
+ * @param context - The current "React Context". Any provided childContextTypes
70
70
* will be passed down the tree.
71
71
*
72
- * @return `true ` to continue walking down the current branch,
72
+ * @return Anything other than `false ` to continue walking down the current branch
73
73
* OR
74
74
* `false` if you wish to stop the traversal down the current branch,
75
75
* OR
@@ -80,18 +80,18 @@ function visitor(element, instance, context) {
80
80
return instance .getData ()
81
81
.then ((value ) => {
82
82
values .push (value);
83
- return value === 4
84
- // prevent traversing "4"'s children
85
- ? false
86
- : true
83
+ // Return "false" to indicate that we do not want to traverse "4"'s children
84
+ return value !== 4
87
85
})
88
86
}
89
- return true
90
87
}
91
88
92
- reactTreeWalker (app, visitor).then (() => {
93
- console .log (values); // [1, 2, 4, 3];
94
- });
89
+ reactTreeWalker (app, visitor)
90
+ .then (() => {
91
+ console .log (values); // [1, 2, 4, 3];
92
+ })
93
+ // since v3.0.0 you need to do your own error handling!
94
+ .catch (err => console .error (err));
95
95
96
96
```
97
97
0 commit comments