Hi just started to learn basics of React and have problem with rendering my component in another component.
<Header> component imported in index.js is not showing.
Index.js:
import React, {Component} from 'react';
import { render } from 'react-dom';
import Header from './components/Header';
import Home from './components/Home';
class App extends Component{
render(){
return(
<div className="container">
<div className="row">
<div className="col-xs-10 col-xs-offset-1">
<div className="col-xs-10 col-xs-offset-1">
<Header />
</div>
</div>
</div>
<div className="row">
<div className="col-xs-10 col-xs-offset-1">
</div>
</div>
</div>
);
}
}
render(<App />, window.document.getElementById('container'));
I have this error:
Error: Minified React error #130; visit http://reactjs.org/docs/error-decoder.html?invariant=130&args[]=undefined&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
Header.js component also:
import React from "react";
export class Header extends React.Component {
render() {
return (
<nav className="navbar navbar-default">
<div className="container">
<div className="navbar-header">
<ul className="nav navbar-nav">
<li>Home</li>
</ul>
</div>
</div>
</nav>
);
}
}
When you open up the URL it says:
Element type is invalid: expected a string (for built-in components)
or a class/function (for composite components) but got: undefined.
Which means:
you forgot to import Header in a file
you import it incorrect way,
Header is not exported in a file
all of the above
After your edit:
You need to fix export (like I wrote above) to:
export default class Header extends React.Component {
you miss the default.
import React from "react";
export default class Header extends React.Component {
render() {
return (
<nav className="navbar navbar-default">
<div className="container">
<div className="navbar-header">
<ul className="nav navbar-nav">
<li>Home</li>
</ul>
</div>
</div>
</nav>
);
}
}
Use the default keyword while exporting the Header.js
it'll start working fine :)
Related
I am trying to make a smooth transition to my second panel of the page by making anchor, as I read on the internet the proper way to do this is by using react.scroll but after doing everything like on the internet my tag simply don't work, while inspecting it with the browser it shows and tag with no destination to go to.
my app comopnent is site in this project:
`
import React, {Component} from 'react';
import Firstpanel from "./firstpanel";
import Secondpanel from "./secondpanel";
import Thirdpanel from "./thirdpanel";
class Site extends Component {
render() {
return (
<div className={"h-screen snap-y snap-mandatory overflow-x-hidden"}>
<div className={"snap-start bg-[url('../public/images/banner_cropped.png')] bg-dark-grey bg-blend-multiply bg-[length:100vw_100vh] h-screen w-screen "}>
<Firstpanel></Firstpanel>
<Secondpanel></Secondpanel>
<Thirdpanel></Thirdpanel>
</div>
</div>
);
}
}
export default Site;
`
then my first panel:
`
import React, {Component} from 'react';
import {Link} from "react-scroll";
class Firstpanel extends Component {
render() {
return (
<section className={" w-screen h-screen flex justify-center items-center flex-col gap-20"}>
<h1 className={"font-bold text-8xl text-beige select-none"}>Welcome to the coding world!</h1>
<p className={"font-bold text-4xl text-beige select-none"}>This site is going to be my personal portfolio for future projects</p>
<Link className={"w-16 h-16 rounded-full mt-12 animate-bounce"} to="sec" spy={true} smooth={true}>
<div className={"rounded-full w-16 h-16 bg-[url('../public/images/second_white_arrow_down.png')] bg-cover cursor-pointer"} type="button">
</div></Link>
</section>
);
}
}
export default Firstpanel;
`
and my second panel:
`
import React, {Component} from 'react';
class Secondpanel extends Component {
render() {
return (
<section className={"snap-start bg-dark-grey h-screen w-screen"}>
<h1 id="home">Hi Paul</h1>
</section>
);
}
}
export default Secondpanel;
`
I tried play with the react.scroll, but even after that it alwyas did nothing
I am following React tutorial.
I have this component.
export default function Header(){
return (<header>
<nav className="nav-bar">
<img src="../img/react.png" className="logo" ></img>
<ul className="nav-items">
<li className="nav-item">Pricing</li>
<li className="nav-item">About</li>
<li className="nav-item">Contact</li>
</ul>
</nav>
</header>)
}
And I am trying to import it in this file
import Header from "./Header";
const rootEl = document.getElementById("root");
function Footer(){
return(
<footer className="footer">
<p># 2022 LastName developed. All rights reserved</p>
</footer>
)
}
function MainContent(){
return(
<div>
<h2>Reasons I want to learn React</h2>
<ol>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
</ol>
</div>
)
}
function CustomPage()
{
return (
<div>
<MainContent/>
<Footer/>
</div>
)
}
ReactDOM.render(<CustomPage/>, rootEl);
I am using CDNs to load react react-dom and babel
When I add import Header from "./Header"; console shows this error:
Uncaught ReferenceError: require is not defined
at <anonymous>:3:15
at eve (transformScriptTags.ts:99:10)
at n (transformScriptTags.ts:173:9)
at s (transformScriptTags.ts:204:11)
at t.forEach.e.src.o.onreadystatechange (transformScriptTags.ts:121:9)
Could it be a problem with CDN links or its something completely eslse?
I am just started working with react js for couple of days it throws error like
src\App.js
Line 2:8: 'navbar' is defined but never used no-unused-vars.this error occurs while i am importing the navbar component into my app.js, i did install eslint package and update my npm version also,i really dontknow what to do .i would really appreciate if u guys provide solution
Below code is my app.js:
import React from 'react';
import navbar from"./components/navbar";
import './App.css';
function App() {
return (
<div className="App">
<navbar />
</div>
);
}
export default App;
below is my navbar.js code which i am trying to import in the app.js
import React, { Component } from 'react';
import{MenuItems} from "./MenuItems";
import "./navbar.css";
class navbar extends Component{
render(){
return(
<nav className="navbarItems">
<h1 className="navbar-logo">React<i className="fab fa-react"></i>
</h1>
<div className="menu-icon"></div>
<ul>
{MenuItems.map((items,index)=>{
return(
<li key={index}>
<a className={MenuItems.cname}href={items.url}>
{items.title}
</a></li>
)
})}
</ul>
</nav>
)
}
}
export default navbar;
App.js
import logo from './logo.svg';
import './App.css';
import Card from './components/Card';
import Accrodion from './components/Accrodion';
function App() {
return (
<>
<div className="container">
<Card />
<Accrodion />
</div>
</>
);
}
export default App;
Card.js
import React from 'react'
export default function Card() {
return (
<div className="card" style="width: 18rem;">
<img src="..." className="card-img-top" alt="..."/>
<div className="card-body">
<h5 className="card-title">Card title</h5>
<p className="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
<ul className="list-group list-group-flush">
<li className="list-group-item">An item</li>
<li className="list-group-item">A second item</li>
<li className="list-group-item">A third item</li>
</ul>
<div className="card-body">
Card link
Another link
</div>
</div>
)
}
Everything works fine when I comment Card component in app.js file, but when I try to use it, nothing is on the webpage. When I inspect the page the root div is empty.
I can't figure out what is the problem here. There is no error in any code file.
Hi I'm a newb to reactjs and I wanted to try pulling some code from other libraries to see how it works. Unfortunately, I'm sort of stuck on trying to use the react-responsive-carousel. I realize this is a really simple question but I have been stuck on this for quite some time now and would appreciate any tips! Thank you so much!
Here is what I'm currently trying:
Index.jsx
import React from 'react';
import {render} from 'react-dom';
import AwesomeComponent from './AwesomeComponent.jsx';
import CarouselComponent from './Carousel.jsx'
class App extends React.Component {
render() {
return (
<div>
<p>Hello React!</p>
<AwesomeComponent />
<CarouselComponent />
</div>
);
}
}
render(<App/>, document.getElementById('container'));
Carousel.jsx:
import React from 'react';
import Carousel from 'react-responsive-carousel';
class CarouselComponent extends React.Component {
render() {
return (
<div>
<Carousel>
<div>
<img src="assets/1.jpeg" />
<p className="legend">Legend 1</p>
</div>
<div>
<img src="assets/2.jpg" />
<p className="legend">Legend 2</p>
</div>
<div>
<img src="assets/3.jpg" />
<p className="legend">Legend 3</p>
</div>
</Carousel>
</div>
);
}
}
export default CarouselComponent;
The error I'm seeing in the console right now is:
Warning: React.createElement: 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 `CarouselComponent`.
in CarouselComponent (created by App)
in div (created by App)
in App
Try importing react-responsive-carousel with braces. Like:
import { Carousel } from 'react-responsive-carousel';