I learn a course with bootstrap and to practice it I wanted to use it in ReactJS. The app is very small, is just a practice, not a real project.
I guess that I do something wrong, because I don't see on my screen the 4 columns. This is what I get
screenshot
So I created a react app
npx create-react-app my-app
and I installed bootstrap and use it.
npm install --save bootstrap
In index.js
import React from 'react';
import ReactDOM from 'react-dom';
import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/js/bootstrap.bundle.min';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
I have the App.js
import React, { Component } from 'react';
import './App.css';
import CardList from './componets/card-lists/card-list';
class App extends Component {
state = {
cards: []
}
componentDidMount() {
fetch('https://jsonplaceholder.typicode.com/users')
.then((response) => response.json())
.then(users => this.setState({ cards: users }))
.catch((error) => {
console.log('Fetch users error ', error)
})
}
render() {
return (
<div className="App">
{this.state.cards.map((card) => {
return <CardList card={card} key={card.id} />
})}
</div>
)
}
}
export default App;
And from here I pass props to card-list.js component.
const cardList = ({ card }) => {
return (
<div>
<div className="container">
<div className="row">
<div className="col-sm-4 col-md-4 col-lg-4 card-list">
<button className="btn btn-danger">click</button>
<h1>{card.name}</h1>
<p>{card.email}</p>
</div>
</div>
</div>
</div>
);
};
export default cardList;
In the css I have just a few lines:
.card-list {
background-color: yellow;
border: 1px solid red;
margin: 10px;
}
Someone please tell me, what I'm doing wrong?
You need to move divs with classes container and row to the App.js.
App.js
render() {
return (
<div className="App">
<div className="container">
<div className="row">
{this.state.cards.map(card => {
return <CardList card={card} key={card.id} />;
})}
</div>
</div>
</div>
);
}
Cardlist
const cardList = ({ card }) => {
return (
<div>
<div className="col-sm-4 col-md-4 col-lg-4 card-list">
<button className="btn btn-danger">click</button>
<h1>{card.name}</h1>
<p>{card.email}</p>
</div>
</div>
);
};
Also please not that Bootstrap grid system uses 12 column, and you are using 4 in classNames, so you have 12 /4 =3 columns, if you want to have 4 columns, you need to use 3 in your components like <div className="col-sm-3 col-md-3 col-lg-3 card-list">
Related
picture of the output https://i.stack.imgur.com/5kxvb.png
code of the carousel
import React from 'react'
import AliceCarousel from 'react-alice-carousel';
import { Link } from 'react-router-dom';
import UseAxios from '../hooks/UseAxios'
import "./Trending.css";
const Trending = () => {
const { response } = UseAxios("search/trending");
return (
{response && response.coins.map(coin => {
return <div className='flex slide' key={coin.item.coin_id}>
<Link to={`/coin/${coin.item.id}`}>
<div>
<AliceCarousel
mouseTracking
infinite
autoPlayInterval={1000}
animationDuration={1500}
disableButtonsControls
autoPlay
>
<img src={coin.item.large} className="mt-0 relative top-30 img" />
<p key={coin.item.coin_id} className="name"> {coin.item.name} </p>
</AliceCarousel>
</div>
</Link>
</div>
})}
</div>
)
}
export default Trending;
note:- library being used is AliceCarousel.
can someone please help me fix the carousel.
I'm having a problem styling this component. I have added some styles but they are not reflecting. What might be the problem?
import React,{useContext} from 'react'
import "./display.css"
import { AppContext } from '../App'
const Display = () => {
const styles={
backgroundColor:"white"
}
const{type, stateWord,definition,synonyms}=useContext(AppContext)
return (
<div styles={styles} className='container'>
<section styles={styles}>
{stateWord && <div style={{color:"white"}}><h4> Word Type: {type}</h4>
<h4>Definition : {definition}</h4>
<h4>Synonyms:</h4>
{synonyms.map((syn)=>{
return<div><h4>{syn}</h4></div>
})}
</div>
}
</section>
</div>
)
}
export default Display
You have written styles instead of style in your divs. Should be style={styles}.
import React,{useContext} from 'react'
import "./display.css"
import { AppContext } from '../App'
const Display = () => {
const styles={
backgroundColor:"white"
}
const{type, stateWord,definition,synonyms}=useContext(AppContext)
return (
<div style={styles} className='container'>
<section style={styles}>
{stateWord && <div style={{color:"white"}}>
<h4> Word Type: {type}</h4>
<h4>Definition : {definition}</h4>
<h4>Synonyms:</h4>
{synonyms.map((syn)=>{
return<div><h4>{syn}</h4></div>
})}
</div>
}
</section>
</div>
)}
export default Display
It's because you misspelled style:
styles={styles}
should be
style={styles}
I am trying to return a test ad on my React app news feed but NPM seems to be lacking documentation. The only thing out there that I can find is from eBayClassifiedsGroup/react-advertising. Here's the code I have for Step1 (see lines 46-54):
import React, { Component } from 'react';
import './App.css';
import News from './News/News';
import SideFeed from './News/SideFeed';
import {
AdvertisingProvider,
AdvertisingSlot,
} from 'react-advertising';
import config from './News/config'
class App extends Component {
constructor(props) {
super(props);
this.state = {
news1: {
type: 'top-headlines',
query: 'sources=bbc-news'
},
news2: {
type: 'everything',
query: 'domains=techcrunch.com&language=en'
},
news3: {
type: 'everything',
query: 'domains=comicbookmovie.com&language=en'
}
};
}
render() {
return (
<div className="container-fluid">
<div className="navbar-fixed">
<nav>
<div className="nav-wrapper indigo lighten-4">
RF News Feed as of 6 DEC 2021
</div>
</nav>
</div>
<div className="row">
<div className="col s8">
<News news={this.state.news1} />
<News news={this.state.news2} />
<div id="banner-ad"
style= { {
width: 300,
height: 250
}}>
<AdvertisingProvider config={config} />
<AdvertisingSlot config={config} />
</div>
</div>
<div className="col s4">
<SideFeed news={this.state.news3}/>
</div>
</div>
</div>
);
}
}
export default App;
Step 2: The only ad dependency is in config.js which is below:
import React from 'react';
const config = {
slots: [
{
id: "banner-ad",
path: "/6355419/Travel/Europe/France/Paris",
sizes: [[300, 250]]
}
]
};
export default config;
Can anyone take a gander or refer me to a resource re: GPT ads implementation for React?
what is the easiest way of asking this in react js?
How can I make a scroll bar using this code.see image expected output?
*[https://i.stack.imgur.com/nex4t.png][1]
import React from 'react';
import ScrollContainer from "react-indiana-drag-scroll";
import './App.css';
const list = new Array(15).fill(1).map((_, index) => index + 1);
const Arrow = ({ text, className }) => {
return <div className={className}>{text}</div>;
};
class Nav extends React.Component{
render(){
return(
<div className="Head">
<div className="Filters">
Filters
</div>
<div className="categories">
<ScrollContainer className="pn-ProductNav">
<div className="pn-ProductNav_Contents ">
{list.map(el => (
<a href="googl.com" className="pn-ProductNav_Link" >
<div className="inner" key={el}>
Chairs
</div>
</a>
))}
</div>
</ScrollContainer>
</div>
</div>
);
}
}
export default Nav;
I keep getting a message that the item I'm trying to access via props is undefined. Can you please tell me why it's not working?
Here is where the instance where the props are attempting to be passed... I'm specifically talking about the tellus and yourTrial props.
import React from 'react'
import Info from './components/Info'
import Upsell from '../../../general/components/order/components/Upsell'
import FormTwo from '../../../general/components/forms/FormTwo'
import Footer from '../../../cbd-desktop/components/layout/Footer'
export default class Order extends React.Component {
render() {
return (
<div>
<div>
<div style={styles.header}>
<img style={styles.leaf} src="./resources/desktop-img/leaves_top.png" />
<img style={styles.logo} src="./resources/desktop-img/logo_white.png" />
</div>
<div style={styles.wrapper}>
<div style={styles.leftWrapper}>
<Info />
<Upsell styles={upsellStyles} />
</div>
<FormTwo styles={formStyles} tellus="Tell us where to send" yourTrial="YOUR TRIAL BOTTLE"} />
</div>
</div>
<Footer style={styles.footer}/>
</div>
)
}
}
And here is where I am trying to display these values on the child... towards the top in two h2s
import React from 'react'
import { connect } from 'react-redux'
import { stepTwoSubmit, saveBillingData } from
'../../actions/formStepTwoActions'
import { addReceiptProduct } from '../../actions/receiptActions'
import FormTwoInputs from './components/FormTwoInputsComponent.jsx'
import Throbber from '../throbber/Throbber'
import FormWarning from './components/FormWarningComponent.jsx'
import Button from '../../../cbd-desktop/components/layout/Button'
const mapStateToProps = state => ({
state:state,
config:state.config,
downsellProduct:state.downsell.downsellProduct || {},
receiptProducts:state.receipt.receiptProducts || []
})
const mapDispatchToProps = {
stepTwoSubmit,
saveBillingData,
addReceiptProduct
}
#connect(mapStateToProps, mapDispatchToProps)
export default class FormTwo extends React.Component {
constructor(props) {
super(props)
componentWillReceiveProps(nextProps) {
let formTwoResponse = nextProps.state.stepTwo.formTwoResponse
this.checkOrderStatus(formTwoResponse)
}
componentDidMount() {
this.fillMainOrder()
this.calculateViewers()
this.calculateTimer()
}
render() {
let { state, props, inputs, onInputFocus, saveInputVal, styles } = this,
CustomTag = props.labels ? 'label' : 'span',
{ submitting, formWarning } = state,
{ invalidInputID, text, visible } = formWarning
return (
<div style={styles.formWrapper}>
<p style={styles.yellowBanner}>{this.state.viewers} people viewing this product right now</p>
<div style={styles.formInnerWrapper}>
<div style={styles.headerWrapper}>
<h2 style={styles.header}>{this.props.tellus}</h2>
<h2 style={styles.header}>{this.props.yourTrial}</h2>
</div>
<div style={styles.weAccept}>
<p style={styles.weAcceptText}>We Accept:</p>
<img style ={styles.cardImage} src="resources/desktop-img/cards.png" />
</div>
<form onSubmit={this.submit}>
<FormTwoInputs onInputFocus={onInputFocus} saveInputVal={saveInputVal} CustomTag={CustomTag} styles={styles} />
<FormWarning visible={visible} invalidInputID={invalidInputID} text={text} />
<Button style={styles.button} buttonText="RUSH MY TRIAL" />
</form>
</div>
<img src="resources/desktop-img/secure.png" />
<div style={styles.urgencyWrapper}>
<div style={styles.urgencyTextWrapper}>
<span style={styles.redText}>{this.state.viewers} people are viewing this offer right now -</span>
<span style={styles.blueText}>{this.state.counter}</span>
</div>
<p style={styles.blueText}>Claim Your Bottle Now</p>
</div>
<Throbber throbberText='Confirming your shipment...' showThrobber={submitting} />
</div>
)
}
}