I am trying to use the following package for image gallery in my react app:
https://github.com/neptunian/react-photo-gallery
The images that I have are not from some URL, as shown in this example:
https://codesandbox.io/s/awesome-bassi-5vn3lvz2n4?from-embed=&file=/index.js:204-210
I tried to store them in a folder in my react application, and save a list of them and send this list to the Gallery as parameter, but the gallery doesn't display those images, only from URL images.
example of the list, Only the first image that is from URL is getting shown:
const photos = [
{
src: "https://source.unsplash.com/Dm-qxdynoEc/800x799",
width: 4,
height: 3
},
{
src: "../assets/PowerToolsRentalsImages/hammers/bosch-gbh-11de/BoschGBH11de.jpg",
width: 4,
height: 3
},
{
src: "../assets/PowerToolsRentalsImages/hammers/bosch-gbh-11de/BoschHammer11.png",
width: 1,
height: 1
},
{
src: "../assets/PowerToolsRentalsImages/hammers/bosch-gbh-11de/BoschHammerRental.jpg",
width: 3,
height: 4
}
];
export default photos;
this is how it looks in my app:
Source URL that is generated in the DOM:
I found a solution,
after reading more I discovered that when using create-react-app you must use import (or require) and can't use img src="..." directly.
So I have edited the list of images to be like the following code, and now it work:
import BoschGBH11de from './BoschGBH11de.jpg';
import BoschHammer11 from './BoschHammer11.png';
import BoschHammerRental from './BoschHammerRental.jpg';
const photos = [
{
src: "https://source.unsplash.com/Dm-qxdynoEc/800x799",
width: 4,
height: 3
},
{
src: BoschGBH11de,
width: 4,
height: 3
},
{
src: BoschHammer11,
width: 1,
height: 1
},
{
src: BoschHammerRental,
width: 3,
height: 4
}
];
export default photos;
Related
I am trying to built a barchart component via "react-chartjs-2". I did pretty much paste my code from here: https://www.c-sharpcorner.com/article/create-different-charts-in-react-using-chart-js-library/.
This is how it looks:
import React from 'react';
import {Bar} from "react-chartjs-2";
const BarChart = () => {
const barChartData = {
labels: ["October", "November", "December"],
datasets: [
{
data: [8137119, 9431691, 10266674],
label: "Infected People",
borderColor: "#3333ff",
backgroundColor: "#547db4",
fill: true
},
{
data: [1216410, 1371390, 1477380],
label: "Deaths People",
borderColor: "#ff3333",
backgroundColor: "#f7813e",
fill: true
}
]
};
const barChart = (
<Bar
type="bar"
width={130}
height={50}
options={{
title: {
display: true,
text: "COVID-19 Cases of Last 3 Months",
fontSize: 15
},
legend: {
display: true, //Is the legend shown?
position: "bottom" //Position of the legend.
}
}}
data={barChartData}
/>
);
return barChart;
};
export default BarChart
Everything seems to be working fine, besides the fact that the options prop is not being recognized by the code.
Did anyone come across a similar issue and can help me out?
Update options prop as bellow.
options = {{
plugins: {
title: {
display: true,
text: "COVID-19 Cases of Last 3 Months"
},
legend: {
display: true,
position: "bottom"
}
}
}}
In my react project I am trying to adjust the appbar width. As of now it is pushed to far to the left as shown in picture below.
The custom class I am trying to use is not doing anything. No error messages, just not working.
Does anyone see what I am doing wrong?
import AppBar from "#mui/material/AppBar";
import Toolbar from "#mui/material/Toolbar";
const drawerWidth = 200; //240
const useStyles = makeStyles((theme) => {
return {
page: {
background: "#f1f1f1",
width: "100%",
padding: useTheme().spacing(3),
},
drawer: {
width: drawerWidth,
},
drawerPaper: {
width: drawerWidth,
},
root: {
display: "flex",
},
active: {
background: "#f4f4f4",
},
appbar: {
width: `calc(100% - ${drawerWidth}px)`,
},
// toolbar: theme.mixins.toolbar,
};
});
Update: You can correct the problem by doing this instead:
appbar: {
width: 'calc(100% - '+drawerWidth+'px)'
},
I think something must have changed between versions of react that allowed his to work and ours not too.
I have the following configurations and it is now working fine
"react": "^16.13.0",
"react-dom": "^16.13.0".
I noticed the code is highlighted differently in my VS Code than in https://www.youtube.com/watch?v=0WbrOfmvjvU&list=PL4cUxeGkcC9gjxLvV4VEkZ6H6H4yWuS58&index=16
Is it possible to style the headers of the react-data-table-component? I tried this
columns: [
{
name: "Name",
selector: "name",
sortable: true,
style: {
background: "orange",
},
},
],
But it styles all the cells underneath that header, not the header itself.
Please let me know if there is documentation that I study this component API from.
I didn't find any mechanism to customize only the header cells, but you could style them with CSS selectors by passing an id in each column object and using the rdt_TableCol class
columns: [
{
name: "Name",
selector: "name",
id: "name",
sortable: true,
style: {
background: "orange",
},
},
],
and in a CSS file
[data-column-id="name"].rdt_TableCol {
background-color: orange;
}
https://codesandbox.io/s/style-header-cell-rdt-c1y35
of course, this method is susceptible to internal changes in the lib, make sure to fix the version and revisit the code if you upgrade the version
In the DataTable props you can assign a style to the customStyles property like so:
import { tableCustomStyles } from './tableStyle.jsx';
<DataTable
customStyles={tableCustomStyles}
/>
And then in the tableStyle.jsx file you can customize all properties of the table like this:
const tableCustomStyles = {
headCells: {
style: {
fontSize: '20px',
fontWeight: 'bold',
paddingLeft: '0 8px',
justifyContent: 'center',
backgroundColor: '#FFA500'
},
},
}
export { tableCustomStyles };
Here is the API reference: https://react-data-table-component.netlify.app/?path=/docs/api-custom-styles--page
And here is the styles.ts file from the repo that shows some of the properties you can manipulate: https://github.com/jbetancur/react-data-table-component/blob/master/src/DataTable/styles.ts
I'm trying to develop a website with Gatsby, React and Bootstrap 5 combined. I found a package react-photo-gallery that I like to use. I got it working perfectly fine under develop. I noticed that this package is causing an error when I run gatsby Build. This is the error produced;
success Rewriting compilation hashes - 0.014s
success Writing page-data.json files to public directory - 0.002s - 0/0 0.00/s
success Building HTML renderer - 2.063s
ERROR
Page data from page-data.json for the failed page "/photos/": {
"componentChunkName": "component---src-pages-photos-js",
"path": "/photos/",
"result": {
"pageContext": {}
},
"staticQueryHashes": []
}
failed Building static HTML for pages - 0.277s
ERROR #95313
Building static HTML failed for path "/photos/"
See our docs page for more info on this error: https://gatsby.dev/debug-html
WebpackError: Minified React error #130; visit https://reactjs.org/docs/error-decoder.html?invariant=130&args[]=object&args[]= for the full message or use the non-minified dev environment for full errors and add itional helpful warnings.
- static-entry.js:286
webpack:/the-last-batten/.cache/static-entry.js:286:22
not finished Caching JavaScript and CSS webpack compilation - 2.571s
not finished Caching HTML renderer compilation - 0.305s
If I click on the minified react error #130 link, it shows;
The full text of the error you just encountered is:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
I can't wrap my mind around how to resolve this issue before continuing. I know it is directly related to this react-photo-gallery, I don't know if it's outdated or conflicting with something. I provided my whole current build below, hopefully, I can get some guidance on what this error is telling me! Thank you.
github link to my build <<
update, Photos.js as per request:
export const photos = [
{
src: "https://source.unsplash.com/2ShvY8Lf6l0/800x599",
width: 4,
height: 3
},
{
src: "https://source.unsplash.com/Dm-qxdynoEc/800x799",
width: 1,
height: 1
},
{
src: "https://source.unsplash.com/qDkso9nvCg0/600x799",
width: 3,
height: 4
},
{
src: "https://source.unsplash.com/iecJiKe_RNg/600x799",
width: 3,
height: 4
},
{
src: "https://source.unsplash.com/epcsn8Ed8kY/600x799",
width: 3,
height: 4
},
{
src: "https://source.unsplash.com/NQSWvyVRIJk/800x599",
width: 4,
height: 3
},
{
src: "https://source.unsplash.com/zh7GEuORbUw/600x799",
width: 3,
height: 4
},
{
src: "https://source.unsplash.com/PpOHJezOalU/800x599",
width: 4,
height: 3
},
{
src: "https://source.unsplash.com/I1ASdgphUH4/800x599",
width: 4,
height: 3
},
{
src: "https://source.unsplash.com/XiDA78wAZVw/600x799",
width: 3,
height: 4
},
{
src: "https://source.unsplash.com/x8xJpClTvR0/800x599",
width: 4,
height: 3
},
{
src: "https://source.unsplash.com/qGQNmBE7mYw/800x599",
width: 4,
height: 3
},
{
src: "https://source.unsplash.com/NuO6iTBkHxE/800x599",
width: 4,
height: 3
},
{
src: "https://source.unsplash.com/pF1ug8ysTtY/600x400",
width: 4,
height: 3
},
{
src: "https://source.unsplash.com/A-fubu9QJxE/800x533",
width: 4,
height: 3
},
{
src: "https://source.unsplash.com/5P91SF0zNsI/740x494",
width: 4,
height: 3
}
];
I've spotted your mistake (now the link works). You are just exporting a photos object (in photos.js) under /pages folder.
Gatsby bases its routing using the folder structure so, when you build the project, Gatsby tries to create a /photos route and it's finding an object (not a React component) and it fails.
If you are just trying to create an object to import/export somewhere else, move it from /pages folder and place it somewhere else. That should fix your issue. Otherwise, if you are just trying to create a /photos page, create a valid syntax.
I have been playing around with react-photo-gallery.
Have installed it together with lightbox and it works just fine when I am displaying online photos.
When I try to display imported ones it's not displaying photo but just frame of it.
import React from 'react';
import Gallery from 'react-photo-gallery';
import Lightbox from 'react-images';
import thumbsup from "../../assets/images/thumbsup.png";
const photos = [
{ src: {thumbsup}, width: 4, height: 3 },
{ src: 'https://source.unsplash.com/Dm-qxdynoEc/800x799', width: 1, height: 1 },
{ src: 'https://source.unsplash.com/qDkso9nvCg0/600x799', width: 3, height: 4 }
];
export default class Sample extends React.Component {
constructor() {
super();
this.state = { currentImage: 0 };
this.closeLightbox = this.closeLightbox.bind(this);
this.openLightbox = this.openLightbox.bind(this);
this.gotoNext = this.gotoNext.bind(this);
this.gotoPrevious = this.gotoPrevious.bind(this);
}
openLightbox(event, obj) {
this.setState({
currentImage: obj.index,
lightboxIsOpen: true,
});
}
closeLightbox() {
this.setState({
currentImage: 0,
lightboxIsOpen: false,
});
}
gotoPrevious() {
this.setState({
currentImage: this.state.currentImage - 1,
});
}
gotoNext() {
this.setState({
currentImage: this.state.currentImage + 1,
});
}
render() {
return (
<div>
<Gallery photos={photos} onClick={this.openLightbox} />
<Lightbox images={photos}
onClose={this.closeLightbox}
onClickPrev={this.gotoPrevious}
onClickNext={this.gotoNext}
currentImage={this.state.currentImage}
isOpen={this.state.lightboxIsOpen}
/>
</div>
)
}
}
I am trying to display it like I did in rest of my components.
import thumbsup from "../../assets/images/thumbsup.png";
{ src: {thumbsup}, width: 4, height: 3 }
Removing the curly braces around {thumbsub} should fix your problem.
const photos = [
{ src: thumbsup, width: 4, height: 3 },
{ src: 'https://source.unsplash.com/Dm-qxdynoEc/800x799', width: 1, height: 1 },
{ src: 'https://source.unsplash.com/qDkso9nvCg0/600x799', width: 3, height: 4 }
];
Like you have it now, the photo object would look like this:
{
src: {
thumbsup: "/..../....png"
},
width: 4,
height: 3
}