gatsby graphql query yields different results in development vs production - reactjs

these two screenshots are showing the same object, returned from a call to useStaticQuery, one in development and one in production. the development object looks the way its supposed to (as it appears in graphiql) but the image on top of production, the object is really weird with totally different fields, and I can't understand why.
to clarify, the first image is of production and the second is development build
Can someone please tell me why this is happening?
here is the whole component:
import React from "react"
import { linkResolver } from "../../utils/linkResolver"
import { useStaticQuery, graphql, Link } from "gatsby"
import Nav from "react-bootstrap/Nav"
import Navbar from "react-bootstrap/Navbar"
import NavDropdown from "react-bootstrap/NavDropdown"
const MyNav = () => {
const data = useStaticQuery(graphql`
query myNavQuery {
prismic {
allAffiliates {
edges {
node {
_meta {
id
type
uid
}
about
affiliate_name
author_name
image_1
image_2
map
}
}
}
}
}
`)
const affiliates = data.prismic.allAffiliates.edges
return (
<Navbar collapseOnSelect variant="light" expand="sm">
<Navbar.Brand href="/">
<div className="nav-logo">Global Paradise Studios</div>
</Navbar.Brand>
<Navbar.Toggle aria-controls="basic-navbar-nav" />
<Navbar.Collapse id="basic-navbar-nav">
<Nav className="ml-auto">
<NavDropdown title="Affiliates" id="basic-navbar-dropdown">
{affiliates.map(affiliate => {
return (
<NavDropdown.Item href={linkResolver(affiliate.node._meta)}>
{affiliate.node.affiliate_name[0].text}
</NavDropdown.Item>
)
})}
</NavDropdown>
<Nav.Link as={Link} to="/">
Home
</Nav.Link>
<Nav.Link as={Link} to="/about">
About
</Nav.Link>
<Nav.Link as={Link} to="/contact">
Contact
</Nav.Link>
</Nav>
</Navbar.Collapse>
</Navbar>
)
}
export default MyNav

Are you using the gatsby-source-prismic-graphql plugin? If so, then it doesn't currently support the useStaticQuery hook. As you've seen it will cause differences in development and prod.
In the README for the plugin you can see how to use the StaticQuery component instead which is supported and works.
https://github.com/birkir/gatsby-source-prismic-graphql#staticquery-and-usestaticquery
Give that a try!

Related

how to move Nav.Link in Bootstrap react Header to the right side?

Hi guys so I'm trying to make header for my web page application using React Bootstrap, but I can't separate the logo with the Nav.link (all of them placed on the left side), but I want the Logo to be on the left side meanwhile the other Nav.link on the right side. In normal bootstrap we just have to add justify-content-end on the list but for React Bootstrap it didn't work, can anyone help me with this please ?
Here's my code:
import '../styles/Header.css'
import { Navbar, Nav } from "react-bootstrap"
import { Link } from 'react-router-dom'
function header() {
return (
<Navbar className="color-nav" variant="dark" expand="lg">
<Navbar.Brand as={Link} to={"/"}>Logo will be Here</Navbar.Brand>
<Navbar.Toggle aria-controls="basic-navbar-nav" />
<Navbar.Collapse id="basic-navbar-nav">
<Nav className="justify-content-end">
<Nav.Link as={Link} to={"/facilities"}>Facilities</Nav.Link>
<Nav.Link as={Link} to={"/room"}>Room</Nav.Link>
<Nav.Link as={Link} to={"/contactus"}>Contact Us</Nav.Link>
<Nav.Link as={Link} to={"/bookingroom"}>Book now</Nav.Link>
</Nav>
</Navbar.Collapse>
</Navbar>
)
}
export default header
You forget to add display flex , so without it is not a flexbox . add d-flex , hope will work.

How can I add navbar band logo at center using react bootstrap in react js

How to add <Navbar.Brand href="#home"> logo at center using react-bootstrap. Please find the below code I wrote.
Please help with this.
import React from 'react'
// import styles from './header.module.css'
// import { HomenetLink } from '../theme/components/Hyperlink'
import { Navbar, Nav } from 'react-bootstrap'
import Navheader from './NavHeader'
import { useTranslation } from 'react-i18next'
const Header = () => {
const { t } = useTranslation()
return (
<div>
<Navbar expand="lg">
<Navheader/>
<Navbar.Brand href="#home"><img
id="homenetlogo"
src="../.././images/homemain.png"
alt="HomeNet"
width="165px"
height="30px;"
/></Navbar.Brand>
<Navbar.Toggle aria-controls="basic-navbar-nav" />
<Navbar.Collapse id="basic-navbar-nav">
<Nav className="ml-auto">
<Nav.Link href="javascript:void(0);" className="coverage-activate" data-activates="coverage">{t('header.coverage')}</Nav.Link>
<Nav.Link href="http://homenet_local/kundeservice" data-collapsible="coverage" >{t('header.customerService')}</Nav.Link>
<Nav.Link href="/minside/" data-collapsible="coverage" >{t('header.myPage')}</Nav.Link>
</Nav>
</Navbar.Collapse>
</Navbar>
</div>
)
}
export default Header
Hi please add a class as below and add css
.brand-center {justify-content: "center"}
<Navbar.Brand href="#home" className="brand-center"><img
id="homenetlogo"
src="../.././images/homemain.png"
alt="HomeNet"
width="165px"
height="30px;"
/></Navbar.Brand>

Can`t change a color of navbar

Navbar doesnt change a background color, i tried to do bg/variant = dark/black , it doesnt change anything
import React, { Component } from 'react';
import {Navbar,Container,Nav} from 'react-bootstrap';
export default class Header extends Component{
render() {
return(
< Navbar collapseOnSelect expand="lg" bg="dark" variant="dark" >
<Container>
<Navbar.Brand href="/">My landing Page</Navbar.Brand>
<Navbar.Toggle aria-controls="basic-navbar-nav"/>
<Navbar.Collapse id="basic-navbar-nav">
<Nav className="mr-auto">
<Nav.Link href="/aboutMe" > About me</Nav.Link>
<Nav.Link href="/aboutUnivercity"> My Univercity</Nav.Link>
<Nav.Link href="/video"> My videos</Nav.Link>
<Nav.Link href="/myMotivate"> MyMotivate</Nav.Link>
</Nav>
</Navbar.Collapse>
</Container>
</Navbar>
)
}
}
Source if needed:
https://github.com/aokhar/SumPract
You have to add bootstrap in your react app.
In your terminal using yarn type:
yarn add bootstrap
Then at the top of your js file add:
import "bootstrap/dist/css/bootstrap.css";
After this hopefully all the colors will render.

REACT Website npm start doesn't start website

When I use NPM Start it opens up a webpage in Chrome but after a while, it says
"Aw, Snap! Something went wrong while displaying this webpage."
GitHub Repository for the code. I can't give a small piece fo code because I don't know what is giving the error.
I would like it to run and show my webpages. Not sure why it isn't working. The first time I started the server using NPM start it gave me this page.
The issue is with the Navbar.js
The issue is your class name here was Nav but Nav was also used in the render function. I have renamed Nav to CustomNavbar and imported the bootstrap nav from the npm package.
change your code to this
import React from 'react';
import { Link } from 'react-router-dom';
import Navbar from 'react-bootstrap/Navbar';
import Nav from 'react-bootstrap/Nav';
import { Button, FormControl, Form, NavDropdown } from "react-bootstrap";
export default class CustomNavbar extends React.Component {
render() {
return (
<div>
<Navbar bg="light" expand="lg">
<Navbar.Brand href="#home">Pawsitively Delicious</Navbar.Brand>
<Navbar.Toggle aria-controls="basic-navbar-nav" />
<Navbar.Collapse id="basic-navbar-nav">
<Nav className="mr-auto">
<Nav.Link href="/">Home</Nav.Link>
<Nav.Link href="AboutUs.js">About Us</Nav.Link>
<NavDropdown title="Ingredients" id="basic-nav-dropdown">
<NavDropdown.Item href="./TypesOfDogTreats">Types of Dog Treats</NavDropdown.Item>
<NavDropdown.Item href="AllIngredients.js">Ingredients</NavDropdown.Item>
</NavDropdown>
</Nav>
<Form inline>
<FormControl type="text" placeholder="Search" className="mr-sm-2" />
<Button variant="outline-success">Search</Button>
</Form>
</Navbar.Collapse>
</Navbar>
</div>
);
} // END OF RENDER
} // END OF Navbar
I was having this issue, for me the problem was caused by adding a button component so i deleted a part of my codes
const checkButtonStyle = STYLES.includes(buttonStyle)?buttonStyle:STYLES[0]
const checkButtonSize = SIZE.includes(buttonSize) ? buttonSize: SIZE[0]
try this link for more options on how to solve it
1:

How to Remove Active Background in React-Bootstrap

How can I remove the active Nav Item background feature in react-bootstrap when selecting Nav Item? It acting abnormally when I use it with 'react-redux' and 'react-router-bootstrap'?
For instance, when I reload the home page, the active background only stays on one of the Nav Items even if I select other Nav Items. Below is the image of the navitem (Dashboard) item is selected and the code for the navbar! Any recommendations would be greatly appreciate!
import React, {Component, PropTypes} from 'react';
import {connect} from 'react-redux';
import {LinkContainer, IndexLinkContainer} from 'react-router-bootstrap';
import {
Nav,
NavItem,
Navbar
} from 'react-bootstrap';
class NavBar extends Component {
render() {
const {authenticated} = this.props;
return (
<Navbar>
<Navbar.Header>
<Navbar.Brand>
Timesheet App
</Navbar.Brand>
<Navbar.Toggle/>
</Navbar.Header>
<Navbar.Collapse>
<Nav>
<IndexLinkContainer to="/">
<NavItem className="nav-link" eventKey={1}>Dashboard</NavItem>
</IndexLinkContainer>
<LinkContainer to="/timesheet/new">
<NavItem className="nav-link" eventKey={2}>Submit Time</NavItem>
</LinkContainer>
<LinkContainer to="/user/Andriy">
<NavItem className="nav-link" eventKey={3}>Andriy Time</NavItem>
</LinkContainer>
{authenticated &&
<LinkContainer to="/signout">
<NavItem className="nav-link" eventKey={4}>Sign Out</NavItem>
</LinkContainer>}
{!authenticated &&
<LinkContainer to="/signin">
<NavItem className="nav-link" eventKey={5}>Sign In</NavItem>
</LinkContainer>}
{!authenticated &&
<LinkContainer to="/signup">
<NavItem className="nav-link">Sign Up</NavItem>
</LinkContainer>}
</Nav>
</Navbar.Collapse>
</Navbar>
);
}
}
NavBar.propTypes = {
authenticated: PropTypes.bool
};
function mapStateToProps(state) {
return {
authenticated: state.auth.authenticated
};
}
export default connect(mapStateToProps)(NavBar);
If you want the active background gone, this can just be a CSS-only fix.
Just override the CSS for the active state background/border/etc to be the same as the non-active state.
Hope this helps.
You should create a class as a variable and use classNames to changed it based on whatever logic you decide to use.
You can then define something in CSS to deal with remove the active background.
For example (taken from the docs):
var btnClass = 'btn';
if (this.state.isPressed) btnClass += ' btn-pressed';
else if (this.state.isHovered) btnClass += ' btn-over';
return <button className={btnClass}>{this.props.label}</button>;
You can use different states to dictate what classes should be added and removed. This also helps with DRY principles as it will prevent you having to repeat yourself across all of the Navbar.
If you set activeKey="", then none of the links are active, and it's only the active key which gets a background.
<Nav activeKey="">
...
</Nav>

Resources