src/resolveRecursive.js
function walkTree(element, context, mergeProps, visitor) {
  const Component = element.type;

  if (typeof Component === 'function') {

    const props = assign({}, Component.defaultProps, element.props, (mergeProps || {}));

    let childContext = context;
    let child;

    // Are we are a react class?
    // https://github.com/facebook/react/blob/master/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js#L66
    if (Component.prototype && Component.prototype.isReactComponent) {

      const instance = new Component(props, context);

      // In case the user doesn't pass these to super in the constructor
      instance.props = instance.props || props;
      instance.context = instance.context || context;

   
      // Override setState to just change the state, not queue up an update.
      // We can't do the default React thing as we aren't mounted "properly"
      // however, we don't need to re-render as well only support setState in
      // componentWillMount, which happens *before* rendere.
      instance.setState = (newState) => {
        instance.state = assign({}, instance.state, newState);
      };

      // This is a poor man's version of
      // https://github.com/facebook/react/blob/master/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js#L181
      if (instance.componentWillMount) {
        instance.componentWillMount();
      }

      if (instance.getChildContext) {
        childContext = assign({}, context, instance.getChildContext());
      }

      // Query we need to resolve first so stop traversing.
      if (visitor(element, instance, context) === false) {
        return;
      }

      child = instance.render();

    } else { // just a stateless functional

      // Query we need to resolve first so stop traversing.
      if (visitor(element, null, context) === false) {
        return;
      }

      child = Component(props, context);
    }


    if (child) {
      walkTree(child, childContext, null, visitor);
    }


  } else { // a basic string or dom element, just get children

    // Query we need to resolve first so stop traversing.
    if (visitor(element, null, context) === false) {
      return;
    }

    // Multiple children, traverse each one.
    if (element.props && element.props.children) {
      React.Children.forEach(element.props.children, (child) => {
        if (child) {
          walkTree(child, context, null, visitor);
        }
      });
    }
  }
}
function walkTree(element, context, mergeProps, visitor) {
  const Component = element.type;

  if (typeof Component === 'function') {

    const props = assign({}, Component.defaultProps, element.props, (mergeProps || {}));

    let childContext = context;
    let child;

    // Are we are a react class?
    // https://github.com/facebook/react/blob/master/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js#L66
    if (Component.prototype && Component.prototype.isReactComponent) {

      const instance = new Component(props, context);

      // In case the user doesn't pass these to super in the constructor
      instance.props = instance.props || props;
      instance.context = instance.context || context;

   
      // Override setState to just change the state, not queue up an update.
      // We can't do the default React thing as we aren't mounted "properly"
      // however, we don't need to re-render as well only support setState in
      // componentWillMount, which happens *before* rendere.
      instance.setState = (newState) => {
        instance.state = assign({}, instance.state, newState);
      };

      // This is a poor man's version of
      // https://github.com/facebook/react/blob/master/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js#L181
      if (instance.componentWillMount) {
        instance.componentWillMount();
      }

      if (instance.getChildContext) {
        childContext = assign({}, context, instance.getChildContext());
      }

      // Query we need to resolve first so stop traversing.
      if (visitor(element, instance, context) === false) {
        return;
      }

      child = instance.render();

    } else { // just a stateless functional

      // Query we need to resolve first so stop traversing.
      if (visitor(element, null, context) === false) {
        return;
      }

      child = Component(props, context);
    }


    if (child) {
      walkTree(child, childContext, null, visitor);
    }


  } else { // a basic string or dom element, just get children

    // Query we need to resolve first so stop traversing.
    if (visitor(element, null, context) === false) {
      return;
    }

    // Multiple children, traverse each one.
    if (element.props && element.props.children) {
      React.Children.forEach(element.props.children, (child) => {
        if (child) {
          walkTree(child, context, null, visitor);
        }
      });
    }
  }
}
function walkTree ( element , context , mergeProps , visitor ) { const Component = element . type ; if ( typeof Component === 'function' ) { const props = assign ( { } , Component . defaultProps , element . props , ( mergeProps || { } ) ) ; let childContext = context ; let child ; // Are we are a react class? // https://github.com/facebook/react/blob/master/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js#L66 if ( Component . prototype && Component . prototype . isReactComponent ) { const instance = new Component ( props , context ) ; // In case the user doesn't pass these to super in the constructor instance . props = instance . props || props ; instance . context = instance . context || context ; // Override setState to just change the state, not queue up an update. // We can't do the default React thing as we aren't mounted "properly" // however, we don't need to re-render as well only support setState in // componentWillMount, which happens *before* rendere. instance . setState = ( newState ) => { instance . state = assign ( { } , instance . state , newState ) ; } ; // This is a poor man's version of // https://github.com/facebook/react/blob/master/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js#L181 if ( instance . componentWillMount ) { instance . componentWillMount ( ) ; } if ( instance . getChildContext ) { childContext = assign ( { } , context , instance . getChildContext ( ) ) ; } // Query we need to resolve first so stop traversing. if ( visitor ( element , instance , context ) === false ) { return ; } child = instance . render ( ) ; } else { // just a stateless functional // Query we need to resolve first so stop traversing. if ( visitor ( element , null , context ) === false ) { return ; } child = Component ( props , context ) ; } if ( child ) { walkTree ( child , childContext , null , visitor ) ; } } else { // a basic string or dom element, just get children // Query we need to resolve first so stop traversing. if ( visitor ( element , null , context ) === false ) { return ; } // Multiple children, traverse each one. if ( element . props && element . props . children ) { React . Children . forEach ( element . props . children , ( child ) => { if ( child ) { walkTree ( child , context , null , visitor ) ; } } ) ; } } }
Recurse an React Element tree, running visitor on each element. If visitor returns `false`, don't call the element's render function or recurse into its child elements
Recurse an React Element tree running visitor on each element . If visitor returns false don t call the element s render function or recurse into its child elements