I have code for react-bootstrap like this.
import React from 'react'
import { Link } from 'react-router-dom'
import { Navbar, NavbarBrand, NavItem, Nav } from 'react-bootstrap'
import './App.css'
import NavbarToggle from 'react-bootstrap/esm/NavbarToggle'
import Routes from './Routes'
import NavbarCollapse from 'react-bootstrap/esm/NavbarCollapse'
import { LinkContainer } from 'react-router-bootstrap'
function App() {
return (
<div className="App container">
<Navbar fluid collapseOnSelect>
<Navbar.Header>
<NavbarBrand>
<Link to="/">Scratch</Link>
</NavbarBrand>
<NavbarToggle />
</Navbar.Header>
<NavbarCollapse>
<Nav pullRight>
<LinkContainer to="/signup">
<NavItem>Signup</NavItem>
</LinkContainer>
<LinkContainer to="/login">
<NavItem>Sign</NavItem>
</LinkContainer>
</Nav>
</NavbarCollapse>
</Navbar>
<Routes />
</div>
)
}
export default App
it occurred errors. The errors message are
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Note: when I omitted Navbar.Header it worked correctly.
NavBar.Header was removed in release v1 of React-bootstrap. Basically, if you add this component, it primarily adds to the DOM a div with a class of navbar-header.
<div class="navbar-header"></div>
If you are curious to know or want to replicate its behavior, you can take a look at this answer: What does "navbar-header" class do in Bootstrap? or take a look at some outdated Bootstrap stylesheet (prior to v4).
If you have the leisure of updating your layout, take a look at the updated examples of React-bootstrap Nav here: https://react-bootstrap.github.io/components/navbar/#navbars
Related
The following code gives an error when I visit the page this component is rendered on:
import React from 'react'
import Layout from '../components/layout'
import SEO from '../components/seo'
import {
Divider,
Card,
Link,
} from '#blueprintjs/core'
const TagPage = ({ pageContext }) => {
const { name, description, tagsCount, questions, } = pageContext
return (
<Layout>
<SEO title={name} description={description} />
<h1>{name}</h1>
<p>{description}</p>
<Divider />
<br/><br/>
{questions.map((q) => {
return (
<>
<Link
to={`tagsQuestion-${q.id}`}
style={{
color: `inherit`,
textDecoration: `none`,
}}
>
<Card interactive='true'>
<p>{q.id}</p>
<p>{q.prompt}</p>
</Card>
</Link>
<br/>
</>
)
})}
</Layout>
)
}
export default TagPage
However if I change:
<Link to={`/question/${q.id}`}>...</Link>
into
<a href={`/question/${q.id}`} >...</a>
then the page will render and be useable without any errors.
This is the current error message I am getting:
(AppContainer, in main (at layout.js:33)) Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Check the render method of `TagPage
Question:
Why can I not use the Link component in this situation?
Info:
questions is an array
TagPage is a page created in gatsby-node.js
Thanks you, for your time, feel free to ask questions as needed.
replace
import {
Divider,
Card,
Link,
} from '#blueprintjs/core'
with
import { Link } from 'gatsby'
import {
Divider,
Card,
} from '#blueprintjs/core'
error - React.Children.only expected to receive a single React element child.
There were quite a few questions with the same context, I tried those solutions but have not found a solution.
The Navbar of the website is what is giving me the error. There is a section over the Navbar which renders properly, when I try to render the Navbar below it throws the error.
import Link from 'next/link'
import Head from '../components/head'
import Download from '../components/nav'
import NavBar from '../components/header'
import Footer from '../components/footer'
import htmlContent from 'html-loader!../legacy/index.html'
const Homepage = () => (
<div>
<Head />
<Download/>
<NavBar />
<div dangerouslySetInnerHTML={{__html: htmlContent}} />
<Footer />
</div>
);
export default Homepage
The footer shows properly, head tag is for all the meta data etc(also works). Github link to all the code is-https://github.com/yohanelly/website-jsx/tree/master/components
The problem is with the whitespace between the Link and the a tag.
<Link href="#"> <a className="menu-links features">Features</a></Link>
should be either
<Link href="#"><a className="menu-links features">Features</a></Link>
or
<Link href="#">
<a className="menu-links features">Features</a>
</Link>
Read the Children in JSX section of the React docs for more info.
I'm new to React and am trying to utilize Semantic-ui-react. I followed the instructions for installing React and Semantic UI React, but am receiving the following error (see links for detailed screenshots, and quote below) in the development console/browser every time I try to add any element from Semantic-ui-react:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.
Check the render method of App.
Screenshot of error message on page
Screenshot of error message in console
When I console.log one of the Semantic-ui-react elements after import, it returns undefined.
Removing the Semantic-ui-react elements, but keeping the JSX resolves the error. I've tried reinstalling both React and Semantic UI React, double checked my imports/exports, and double checked my syntax, but I can't locate the problem.
REPO: https://github.com/LATAEVIA/SS-Artistpage
Package.json
"dependencies": {
"react": "^16.1.0",
"react-dom": "^16.1.0",
"react-scripts": "1.0.17"
"react-scripts": "1.0.17",
"semantic-ui-css": "^2.2.12",
"semantic-ui-react": "^0.76.0"
Index.html
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.12/semantic.min.css"></link>
Index.js
import React from 'react';
import ReactDOM from 'react-dom';
// import './index.css';
import 'semantic-ui-css/semantic.min.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
App.js
import React, { Component } from 'react';
import './App.css';
import { Button, Icon, Header, Container } from 'semantic-ui-css/semantic.min.css';
console.log(Button);
class App extends Component {
render() {
return ([
<Container>
<div key={0}>
<Header>
<img alt="Artist Image" />
<h1>Artist Name</h1>
<p>
Artist Bio
</p>
</Header>
</div>,
<div key={1}>
<h2>(Artist Name) Songs That Feel Like:</h2>
<form>
<input type="checkbox" name="mood_tags" value="Calm" /> Calm<br/>
<input type="checkbox" name="mood_tags" value="Mellow" /> Mellow<br/>
<input type="submit" value="Submit" />
<Button size='small' color='green'>
<Icon name='download' />
Download
</Button>
</form>
</div>
</Container>
]);
}
}
export default App;
Replace :
import { Button, Icon, Header, Container } from 'semantic-ui-css/semantic.min.css';
By:
import { Button, Icon, Header, Container } from 'semantic-ui-react';
import 'semantic-ui-css/semantic.min.css';
Indeed, components cannot be imported from css file .
I develop react + meteor app, then I got error like this,
I try to add navigation https://react-bootstrap.github.io/components.html#navigation, get data in this tutorial . I try to add this const like below way
MainComponent
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { Meteor } from 'meteor/meteor';
import { createContainer } from 'meteor/react-meteor-data';
import { Button } from 'react-bootstrap';
import AccountsUIWrapper from './AccountsUIWrapper.jsx';
// App component - represents the whole app
export default class Home extends Component {
constructor(props) {
super(props);
this.state = {
hideCompleted: false,
};
}
render() {
const navbarInstance = (
<Navbar>
<Navbar.Header>
<Navbar.Brand>
React-Bootstrap
</Navbar.Brand>
</Navbar.Header>
<Nav>
<NavItem eventKey={1} href="#">Link</NavItem>
<NavItem eventKey={2} href="#">Link</NavItem>
<NavDropdown eventKey={3} title="Dropdown" id="basic-nav-dropdown">
<MenuItem eventKey={3.1}>Action</MenuItem>
<MenuItem eventKey={3.2}>Another action</MenuItem>
<MenuItem eventKey={3.3}>Something else here</MenuItem>
<MenuItem divider />
<MenuItem eventKey={3.4}>Separated link</MenuItem>
</NavDropdown>
</Nav>
</Navbar>
);
return (
<div>
{navbarInstance}
<div className="container">
<div className="row">
<div className="navbar nav-inline">
<AccountsUIWrapper />
</div>
</div>
<header>
<h1>School Attendance</h1>
<h3>Lecturer Report</h3>
</header>
<h4>This is home</h4>
</div>
</div>
);
}
}
but I got bellow error. and there reason as like me.
There add some import
import { Button, Navbar, Nav, NavItem, NavDropdown, MenuItem } from 'react-bootstrap';
like this then vanish the error, but I got like this
I want to correct way to Navbar add
The classes you call in render are not defined.
Where you have import {Button} from 'react-bootstrap' you need to import every component that you plan on using in your file ( that is part of that framework ).
The solution would be adding Navbar, like so:
import { Button, Navbar } from 'react-bootstrap'
Also have you included Bootstrap styles in your project?
https://react-bootstrap.github.io/getting-started/introduction
firstly install react bootstrap
npm install react-bootstrap bootstrap
// or use yarn
yarn add react-bootstrap bootstrap
also you need to import Navbar as well you can use this code
import Navbar from 'react-bootstrap/Navbar'
// or
import { Navbar } from 'react-bootstrap'
for the styling you need to add bootstrap styles. How and which Bootstrap styles you include is up to you, but the simplest way is to include the latest styles from the CDN.
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk"
crossorigin="anonymous"
/>
I get this error,
Warning: validateDOMNesting(...): <a> cannot appear as a descendant of <a>. See HeaderNavigation > NavItem > SafeAnchor > a > ... > Scrollchor > a.
With this code,
import React from 'react';
import Navbar from 'react-bootstrap/lib/Navbar'
import {Nav, NavItem} from 'react-bootstrap';
import Scrollchor from 'react-scrollchor';
export default React.createClass ({
render() {
return (
<div>
<Navbar inverse fixedTop>
<Navbar.Header>
<Navbar.Brand>
M2 Consulting
</Navbar.Brand>
</Navbar.Header>
<Nav pullright bsStyle = "pills" active>
<NavItem><Scrollchor to="#services">Services</Scrollchor></NavItem>
<NavItem><Scrollchor to="#work">Latest Work</Scrollchor></NavItem>
<NavItem><Scrollchor to="#contact">Contact Us</Scrollchor></NavItem>
</Nav>
</Navbar>
</div>
);
}
});
I believe this is due to NavItem and Scrollchor both using a href,
How can I retain use of the styling of NavItem while using Scrollchor?
Appreciate the help.
NavItem has an <a> in it, so I removed it and simply used <li> instead.