Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 304
nimbus_debug Avatar asked Oct 21 '18 14:10

nimbus_debug


People also ask

Why is props undefined In React?

The "Cannot read property 'props' of undefined" error occurs when a class method is called without having the correct context bound to the this keyword. To solve the error, define the class method as an arrow function or use the bind method in the classes' constructor method.

How do you get the DOM element in React?

In React we can access the DOM element using Refs. Refs provide a way to access DOM nodes or React elements created in the render method. Creating Refs: Refs are created using React. createRef() and attached to React elements via the ref attribute.

Does React interact with DOM?

In React, we don't actually interact with the browser DOM.

What is DOM element in React?

DOM: DOM stands for 'Document Object Model'. In simple terms, it is a structured representation of the HTML elements that are present in a webpage or web-app. DOM represents the entire UI of your application. The DOM is represented as a tree data structure.


2 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>
like image 161
Aamir Jamal Avatar answered Sep 28 '22 11:09

Aamir Jamal


DO NOT USE your component in Switch method like these:

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

Only use Redirect/Route methods in Switch only!!

like image 45
rttss_sahil Avatar answered Sep 28 '22 11:09

rttss_sahil