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>
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.
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.
In React, we don't actually interact with the browser DOM.
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.
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!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With