I tried to use react-bootstrap's Navbar component in the typescript template and I found below warning in Chrome console.
index.js:1 Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Transition which is inside StrictMode. Instead, add a ref directly to the element you want to reference.
in div (created by Context.Consumer)
in Transition (created by Collapse)
in Collapse (created by Context.Consumer)
in NavbarCollapse (at NavigationBar.tsx:10)
in nav (created by Navbar)
in Navbar (at NavigationBar.tsx:7)
in NavigationBar (at App.tsx:8)
in div (at App.tsx:7)
in App (at src/index.tsx:10)
in StrictMode (at src/index.tsx:9)
Below is the code
import React from 'react';
import './NavigationBar.css';
import { Navbar, Nav, NavDropdown } from 'react-bootstrap';
function NavigationBar() {
return (
<Navbar bg="light" expand="lg">
<Navbar.Brand href="#home">React-Bootstrap</Navbar.Brand>
<Navbar.Toggle aria-controls="basic-navbar-nav" />
<Navbar.Collapse id="basic-navbar-nav">
<Nav className="mr-auto">
<Nav.Link href="#home">Home</Nav.Link>
<Nav.Link href="#link">Link</Nav.Link>
<NavDropdown title="Dropdown" id="basic-nav-dropdown">
<NavDropdown.Item href="#action/3.1">Action</NavDropdown.Item>
<NavDropdown.Item href="#action/3.2">Another action</NavDropdown.Item>
<NavDropdown.Item href="#action/3.3">Something</NavDropdown.Item>
<NavDropdown.Divider />
<NavDropdown.Item href="#action/3.4">Separated link</NavDropdown.Item>
</NavDropdown>
</Nav>
</Navbar.Collapse>
</Navbar>);
}
export default NavigationBar;
Even the Navbar component's collapse function is working, what should I do to for warning message.
Note: findDOMNode is an escape hatch used to access the underlying DOM node. In most cases, use of this escape hatch is discouraged because it pierces the component abstraction. It has been deprecated in StrictMode .
Apparently it's a github issue already. here
Since this is a warning (and not an error) therefore, your app will continue to work just fine.
Facebook will eventually deprecate findDOMNode
as it blocks certain improvements in React in the future
react-bootstrap
will eventually upgrade it's code to drop using findDomNodes
for other suitable alternatives.
Best solution for me was to set animation to false as suggested above however, you need to do it with animation="false" NOT animation={false} or you will get another warning. You will also need to add it to the Navbar.Collapse tag so:
<Navbar animation="false" ...>
...
<Navbar.Collapse animation="false" ...>
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