Hero-slider shows slider functions but don't shows images - reactjs

I have a small app with react where I used hero-slider for the image slider. it shows the result as slider and background color. but the images are not shown.
here is my basicslider.js
import React from "react";
// JSX
import HeroSlider, { Slide, Nav } from "hero-slider";
// Images
const bogliasco = "https://i.imgur.com/Gu5Cznz.jpg";
const countyClare = "https://i.imgur.com/idjXzVQ.jpg";
const craterRock = "https://i.imgur.com/8DYumaY.jpg";
const giauPass = "https://i.imgur.com/8IuucQZ.jpg";
const BasicSlider = () => {
return (
<HeroSlider
slidingAnimation="left_to_right"
orientation="horizontal"
initialSlide={1}
onBeforeChange={(previousSlide, nextSlide) =>
console.log("onBeforeChange", previousSlide, nextSlide)
}
onChange={nextSlide => console.log("onChange", nextSlide)}
onAfterChange={nextSlide => console.log("onAfterChange", nextSlide)}
style={{
backgroundColor: "rgba(0, 0, 0, 0.33)"
}}
settings={{
slidingDuration: 250,
slidingDelay: 100,
shouldAutoplay: true,
shouldDisplayButtons: true,
autoplayDuration: 5000,
height: "100vh"
}}
>
<Slide
background={{
backgroundImage: giauPass,
backgroundAttachment: "fixed"
}}
/>
<Slide
background={{
backgroundImage: bogliasco,
backgroundAttachment: "fixed"
}}
/>
<Slide
background={{
backgroundImage: countyClare,
backgroundAttachment: "fixed"
}}
/>
<Slide
background={{
backgroundImage: craterRock,
backgroundAttachment: "fixed"
}}
/>
<Nav />
</HeroSlider>
);
};
export default BasicSlider;
Here is app.js
import React from 'react'
import './app.css'
import BasicSlider from './containers/basicslider/BasicSlider';
const App = () => {
return (
<div className='App'>
<BasicSlider/>
</div>
)
}
export default App
Here is my index.js
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
ReactDOM.render(<App />, document.getElementById("root"));
Everything is fine. No error. No warning. Just it shows like this
enter image description here
I want to make the images visible. How can I solve it?

You cannot add component as backgroundImage, the correct way:
<Slide
background={{
backgroundImageSrc: bogliasco,
backgroundAttachment: "fixed"
}}
/>

Related

react typescript stitches css prop problem, not work

i'm currently working on a project using stitches with cra but i've stuck to a problem with css props.
here's my code
Texts/index.tsx
import React from 'react';
import { TextStyle } from './textStyle';
const Texts = ({ text, css }: PropsType) => {
console.log(css);
return (
<>
<TextStyle css={{ ...css }} >
<>{text}</>
</TextStyle>
</>
);
};
export default Texts;
and this index.tsx is exported to another components
Container/index.tsx
import { styled, css } from '../../../stitches.config';
// atoms
import Texts from 'src/components/atoms/texts';
const PageContainer = () => {
return (
<Container>
<Contents >
<div>
<Texts
css={{ color: 'red' }}
/>
<Texts
css={{ paddingTop: '20px' }}
/>
</div>
</Contents>
</Container>
);
};
export default PageContainer;
as you can see with the above code, contains css as its child but css is never rendered at all
can anyone help me with this issue?
FYI, console.log(css); returned undefined to me.
Thank you in advance!

I want to display Google Adsense on my gatsby.js site. However, it is not showing up

I want to display Google Adsense on my gatsby.js site. However, it is not showing up.
LeftSideSection is called in Layout.js.
I am running it in a local environment.
And I don't have a domain for my site.
I don't register my site's domain in GoogleAdsense and
I have created an Ad unit.
export
[
googleAdsense.js
import React from "react"
import * as styles from "./LeftSideSection.module.css";
import {Adsense} from './googleAdsense'
import React, { useEffect } from 'react'
export const Adsense = ({ path }) => {
useEffect(() => {
;(window.adsbygoogle = window.adsbygoogle || []).push({})
}, [path])
return (
<ins
className="adsbygoogle"
style={{ "display": "block" , textAlign: "center",width:`100%` ,height:`100%`}}
data-ad-client="ca-pub-xxxxxxxxx"
data-ad-slot="xxxxxxx"
data-ad-format="auto"
data-full-width-responsive="true"
data-adtest="on"
/>
)
}
LeftSideSection.js
const LeftSideSection = (props) => {
const { title, children } = props;
const path = props.location?.pathname || '';
return (
<section className={styles.container}>
<p>ads</p>
<Adsense path={path} />
</section>
);
};
export default LeftSideSection;
Layout.js
import React from "react";
import Header from "./Header";
import * as styles from "./Layout.module.css";
import 'bootstrap/dist/css/bootstrap.min.css';
import herderImage from '../images/header.png'
import {Navbar} from 'react-bootstrap'
import RightSideSection from "./RightSideSection";
import LeftSideSection from "./LeftSideSection";
import { Link } from "gatsby";
import { useBreakpoint } from 'gatsby-plugin-breakpoints';
import HeaderRss from "./HeaderRss";
const Layout = ({ children }) => {
const breakPoints = useBreakpoint();
return (
breakPoints.pc ?
<>
<Navbar.Brand as={Link} href='/' >
<img src={herderImage} style={{width:`100%`,height:`200px`,}}/>
</Navbar.Brand>
<Header />
<div className={styles.container}>
<div className={styles.LeftSideSection}>
<LeftSideSection />
</div>
<div className={styles.RightSideSection}>
<RightSideSection />
</div>
<div className={styles.mainPane}>
<div className={styles.headerRssContainer}>
<HeaderRss/>
</div>
{children}
</div>
</div>
<footer className={styles.footer}>
© {new Date().getFullYear()},
{`title`}
</footer>
</>:
);
};
export default Layout;
enter image description here
You are not loading the <script> that the console is suggesting. Try using the Helmet component to do something like:
import React from "react"
import * as styles from "./LeftSideSection.module.css";
import {Adsense} from './googleAdsense'
import React, { useEffect } from 'react'
export const Adsense = ({ path }) => {
useEffect(() => {
;(window.adsbygoogle = window.adsbygoogle || []).push({})
}, [path])
return <>
<Helmet>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</Helmet>
<ins
className="adsbygoogle"
style={{ "display": "block" , textAlign: "center",width:`100%` ,height:`100%`}}
data-ad-client="ca-pub-xxxxxxxxx"
data-ad-slot="xxxxxxx"
data-ad-format="auto"
data-adtest="on"
data-full-width-responsive="true"
/>
</>
}
I still don't know what's import {Adsense} from './googleAdsense', this line may collide with the naming of the component that you are defining (both are Adsense). If the issue persists, try changing the name.
To make the ads available on localhost, set the data-adtest as on.
In addition, you can try using a React-based solution like the one that react-adsense suggests.
Double-check and remove AdBlocks (or similar).
However, the image of the ad did not show up.
This can be caused by the localhost. Try deploying the site to check it in a real domain.

How to Change footer value in antd layout when i click on button inside route based component in reactjs [duplicate]

This question already exists:
How to Change footer value inside antd layout when i click on button inside any route based component in reactjs
Closed 1 year ago.
I have used antd Layout with footer for Reactjs application. How to change value of footer when I click on button inside numbers component. I have used antd layout like this
https://ant.design/components/layout/
Code For Above Functionality Like:
When i click on button how to display Input value on Footer Label.
Mainly Two component Like :
WebSiteLayout.js (Footer inside them)
NumberList.js (Button and Input value inside them)
How to pass value from NumberList.js component to WebSiteLayout.js
WebSiteLayout.js
import React from "react";
import { withRouter, Switch, Link } from "react-router-dom";
import NumbersList from "../pages/Numbers/NumbersList";
import AuthenticatedRoute from '../../AuthenticatedRoute';
import './WebLayout.css';
import '../../../../assets/css/app.css';
import { Layout, Button, Menu, Popover, Spin, Select, Checkbox, Row, Col, Form, notification } from 'antd';
const { Header, Sider, Content, Footer } = Layout;
const { SubMenu } = Menu;
import {
PhoneOutlined,
} from '#ant-design/icons';
const WebSiteLayout = ({ location, row }) => {
return (
<Layout>
<Sider trigger={null} collapsible collapsed={collapsed}>
<div className="topbar1">
<div className="topbar-left">
</div>
</div>
<Menu theme="dark" mode="inline">
<Menu.Item key="/numbers" icon={<PhoneOutlined style={{ fontSize: '18px' }} />} title="Numbers" >
<span>Numbers</span>
<Link to="/numbers" />
</Menu.Item>
</Menu>
</Sider>
<Layout className="site-layout" hasSider={true} style={{ height: "100vh" }}>
<Content
className="site-layout-background"
style={{
padding: 24,
height: '80px',
minHeight: 280,
}}
>
<Switch>
<AuthenticatedRoute path='/numbers' component={NumbersList} />
</Switch>
<Footer style={{ position: "fixed", bottom: "0px", right: "0px", background: "#c2c2c2", padding: "15px 25px" }}>
Display Numbers Field Value
</Footer>
</Content>
</Layout>
</Layout>
);
};
export default withRouter(WebSiteLayout)
NumberList.js
import React, {Component} from 'react';
import 'antd/dist/antd.css';
import { withRouter } from "react-router";
import { Button, Input } from 'antd';
class NumbersList extends Component {
constructor(props) {
super(props);
this.state = {
value:''
}
}
sendValueToFooter = () => {
console.log(this.state.value);
}
render() {
return (
<div class="container-fluid">
<h4 class="page-title float-left">Numbers</h4>
<Input placeholder="Basic usage" value={this.state.value} onChange={(e)=>{this.setState({value : e.target.value})}}/>
<br></br>
<Button type="primary" onClick={this.sendValueToFooter}>
Click Here To Send Value On Footer
</Button>
</div>
)
}
}
export default withRouter(NumbersList)
When I click on button how to display Input value on Footer Label.

Video Render in NEXTJS

I'm using NextJS and I was trying to put a video as a background. In the FIRST render everything works fine, but when I reload the screen, the video doesn't run in the autoplay mode.
Code:
import React from 'react'
import MainHeader from '../components/MainHeader'
import { Container } from '../styles/pages/Home'
const Home: React.FC = () => {
return (
<Container>
<MainHeader />
<video autoPlay style={{ width: '500px', height: '500px' }}>
<source src="/blue.mp4" />
</video>
</Container>
)
}
export default Home
How can I fix that?
I have added the loop to your code. I hope it solves your problem
import React from 'react'
import MainHeader from '../components/MainHeader'
import { Container } from '../styles/pages/Home'
const Home: React.FC = () => {
return (
<Container>
<MainHeader />
<video autoPlay loop style={{ width: '500px', height: '500px' }}>
<source src="/blue.mp4" />
</video>
</Container>
)
}
export default Home
Just for information, the video with sound can't reload even with loop and autoplay, the browser don't allowed.
The solution is put autoplay, loop, muted and controls for could you start the sound if you want.

Anchor Link under Map Component not clickable

I am writing my first React App (using create-react-app) and I wrote a Map component using google-maps-react. However, the links BELOW the map cannot be clicked.
Actually, on my webpage, this issue is present only on small and medium-sized screens, while it works perfectly on large screens (small, medium and large as defined by materializecss). I tried to reproduce the issue on a minimal working example, without materialize, just using the boilerplate code created by `npx create-react-app my-app' and adding the following:
MapComponent.js
import React from 'react';
import { Map, GoogleApiWrapper } from 'google-maps-react';
const mapStyles = {
width: '80vw',
height: '45vw',
marginLeft: 'auto',
marginRight: 'auto',
display: 'block'
};
const MapComponent = (props) => {
return (
<div className="MapComponent">
<div>
Google
</div>
<Map
google={props.google}
zoom={10}
style={mapStyles}
initialCenter={{
lat: 40,
lng: 12
}}
/>
<div>
Google
</div>
</div>
);
}
export default GoogleApiWrapper({
apiKey: "Key"
})(MapComponent);
and then in App.js:
import React, { Component } from 'react';
import MapComponent from './MapComponent';
class App extends Component {
render() {
return (
<div className="Appr">
<MapComponent />
</div>
);
}
}
export default App;
(the key is not reported in the example, so maps will display the frame with an error message, but the issue is the same with the key). The first link to google.com can be clicked and works, while the second does not. Any solution/workaround?
Finally, I went through the source code of google-maps-react and found the solution. It is very simple but rather undocumented. Apart from style the Map component accepts a containerStyle prop, allowing to change the tyle of the container wrapping Map. By default, the position is set to position: absolute giving the aforementioned behavior. The following code solves the issue for me:
import React from 'react';
import { Map, GoogleApiWrapper } from 'google-maps-react';
const mapStyles = {
width: '80vw',
height: '45vw',
marginLeft: 'auto',
marginRight: 'auto',
display: 'block'
};
const containerStyle = { {/* Added style */}
position: 'static'
}
const MapComponent = (props) => {
return (
<div className="MapComponent">
<div>
Google
</div>
<Map
google={props.google}
zoom={10}
style={mapStyles}
containerStyle={containerStyle} {/* Added prop */}
initialCenter={{
lat: 40,
lng: 12
}}
/>
<div>
Google
</div>
</div>
);
}
export default GoogleApiWrapper({
apiKey: "Key"
})(MapComponent);

Resources