React does not recognize the `computedMatch` prop on a DOM element.

Viewed 20042

I am using react typescript with bootstrap-v3, the problem is about Breadcrumb and react-router-dom:

a warning is prompt from react: React does not recognize the computedMatch prop on a DOM element.

how does this computedMatch come from? I'm using latest react-bootstrap:

the first line is the html node with strange computedmatch attribute:

<ol computedmatch="[object Object]" location="[object Object]" role="navigation" aria-label="breadcrumbs" class="breadcrumb"><li class=""><span href="#" role="button"><a href="/">Home</a></span></li><li class=""><span href="#" role="button"><a href="/">React</a></span></li><li class=""><span href="#" role="button"><a href="/name">Author</a></span></li></ol>

the following are the Breadcrumb.js lib file:

import _extends from "@babel/runtime-corejs2/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime-corejs2/helpers/esm/objectWithoutPropertiesLoose";
import _inheritsLoose from "@babel/runtime-corejs2/helpers/esm/inheritsLoose";
import classNames from 'classnames';
import React from 'react';
import BreadcrumbItem from './BreadcrumbItem';
import { bsClass, getClassSet, splitBsProps } from './utils/bootstrapUtils';

var Breadcrumb =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(Breadcrumb, _React$Component);

  function Breadcrumb() {
    return _React$Component.apply(this, arguments) || this;
  }

  var _proto = Breadcrumb.prototype;

  _proto.render = function render() {
    var _this$props = this.props,
        className = _this$props.className,
        props = _objectWithoutPropertiesLoose(_this$props, ["className"]);

    var _splitBsProps = splitBsProps(props),
        bsProps = _splitBsProps[0],
        elementProps = _splitBsProps[1];

    var classes = getClassSet(bsProps);
    return React.createElement("ol", _extends({}, elementProps, {
      role: "navigation",
      "aria-label": "breadcrumbs",
      className: classNames(className, classes)
    }));
  };

  return Breadcrumb;
}(React.Component);

Breadcrumb.Item = BreadcrumbItem;
export default bsClass('breadcrumb', Breadcrumb);

my tsx code is:

<Router>
          <Switch>
            <Breadcrumb computedMatch={undefined}>
              <Breadcrumb.Item componentClass="span">
                <Link to="/">Home</Link>
              </Breadcrumb.Item>
              <Breadcrumb.Item componentClass="span">
                <Link to="/">React</Link>
              </Breadcrumb.Item>
              <Breadcrumb.Item active={false} componentClass="span">
                <Link to="/name">Author</Link>
              </Breadcrumb.Item>
            </Breadcrumb>
            <Route path="/:name" component={gridInstance} />
          </Switch>
        </Router>
3 Answers

You are getting this warning because of the way you have placed your <Switch> tag. Keep only <Route/> and <Redirect/> tags within the<Switch> tags to get rid of the warning.

Something like this:

<Router>
    <Breadcrumb computedMatch={undefined}>
      <Breadcrumb.Item componentClass="span">
        <Link to="/">Home</Link>
      </Breadcrumb.Item>
      <Breadcrumb.Item componentClass="span">
        <Link to="/">React</Link>
      </Breadcrumb.Item>
      <Breadcrumb.Item active={false} componentClass="span">
        <Link to="/name">Author</Link>
      </Breadcrumb.Item>
    </Breadcrumb>
    <Switch>
      <Route path="/:name" component={gridInstance} />
    </Switch>
</Router>

DO NOT USE your component in Switch method like these:

<Switch>
{component}
<Component /> 
</Switch>

Only use Redirect/Route methods in Switch only!!

I made a breadcrumb by simple using breadcrumb css class in bootstrap. (which means not using the Breadcrumb and Breadcrumb.Item from bootstrap-v3) and the problem is solved. Breadcrumb in bootstrap-v3 is surely not a simple container, but has some state that is not included in the doc.

const MyBreadcrumb = () => (
  <Router>
    <div>
      <ol className="breadcrumb">
        <li>
          <Link to="/">Home</Link>
        </li>
        <li>
          <Link to="/about">About</Link>
        </li>
        <li>
          <Link to="/topics">Topics</Link>
        </li>
      </ol>

      <hr />
    </div>
  </Router>
);
Related