Module not found: Can't resolve 'react-table/react-table.css' - reactjs

I have create the app using create-react-app. Then I installed the react-table package(using command npm install --save react-table). When I started my application I am getting Module not found: Can't resolve 'react-table/react-table.css' this error.
Any suggestion how to resolve this. Thanks in advance !

You should install react-table version-6.
$ npm install react-table-6
and then import these,
import ReactTable from "react-table-6";
import "react-table-6/react-table.css"

Sadly react-table v7 doesn't support react-table.css file.
If you want to reuse react-table.css, I recommend using v6.
Here goes my example:
https://codesandbox.io/s/react-table-custom-pagination-1onbd
We can easily create custom css for react-table and there is a lot of examples online.

The current version of react-table is 7.
React table 6th version supports the cs,
You should install react-table version-6.
$ npm install react-table-6
next import it in file
import ReactTable from "react-table-6";
import "react-table-6/react-table.css"
**Sample Code**
import React, {useState, useEffect,Component } from "react";
import "../node_modules/bootstrap/dist/css/bootstrap.min.css";
import $ from 'jquery';
import './Markettable.css';
import 'datatables.net';
import 'datatables.net-dt/css/jquery.dataTables.css';
import axios from 'axios';
import ReactTable from "react-table-6";
import "react-table-6/react-table.css" ;
export default class Markettable extends Component {
constructor(props){
super(props)
this.state = {
market: [],
loading:true
}
}
async getMarketPrice(){
const res = await axios.get(`https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&sparkline=false&price_change_percentage=1h%2C24h%2C7d`)
console.log(res.data)
this.setState({loading:false, market: res.data})
}
componentDidMount(){
this.getMarketPrice()
}
render() {
const columns = [{
Header: 'ID',
accessor: 'name',
sortable: true,
}
,{
Header: 'Name',
accessor: 'precentage' ,
},
{
Header: 'Website',
accessor: 'market_cap',
}
]
return (
<>
<div className= "container-fluid">
<div className="header">
<h2 className= "page-header text-center text-uppercase">
<b> Marketing Prices </b>
</h2>
<ul className="breadcrumb ">
<li><a href="#" style={{color: 'black'}}>Home</a></li>
<li className="active" style={{color: ' #660000'}}>Marketing Price</li>
</ul>
</div>
<div className ="row">
<div className = "col-12">
<div className="card">
<div className="card-action">
<div className="marketprice">
<div className="row">
<div className ="col-12">
<div className ="card">
<div className="card-body">
<h2> <b> <u> MARKETING PRICE TABLE </u> </b> </h2>
</div>
<br/>
<div className="card-body--">
<ReactTable className ="text-center"
data={this.state.market}
columns={columns}
/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</>
)
}
}

import ReactTable from "react-table-6";
This one should be "react-table-v6"
import "react-table-v6/react-table.css"

Related

Swiper Js cannot read properties of undefined ('reading includes)

I have this component I wrote for reviews using swiperjs in a react and nextjs project but I have been getting an error with seems to be coming from this reviews component saying Unhandled Runtime Error TypeError: Cannot read properties of undefined (reading 'includes')
I can't figure out why but when I comment out all the code in that component, everything seems to work fine. I have also tried upgrading swiper in package.json and also tried downgrading react but the error will not go away. Please help me figure out what I could be doing wrong using the code below
components/Reviews.jsx
import React, { useRef, useState, useEffect } from 'react'
import {ReviewForm} from '../components'
import { FaFacebookSquare, FaGithubSquare, FaTwitterSquare, FaInstagramSquare, FaYoutubeSquare } from 'react-icons/fa'
import {MdOutlineArrowForward} from 'react-icons/md'
import { getReviews } from '../services'
import { Swiper, SwiperSlide } from "swiper/react";
import moment from 'moment'
// Import Swiper styles
import "swiper/css";
import "swiper/css/pagination";
import "swiper/css/navigation";
// import required modules
import { Pagination, Navigation } from "swiper";
const Reviews = () => {
const [reviews, setReviews] = useState([]);
useEffect(() => {
getReviews()
.then((newReviews) => setReviews(newReviews))
}, [])
return (
<div className='reviewsBgBlack'>
<div><h4 className="font-normal py-5 tracking-wide lg:text-5xl md:text-3xl text-center text-[#D72A06]">CLIENTS REVIEWS <span className='text-white'>ABOUT <br />THE QUALITY OF OUR WORK</span></h4></div>
<Swiper
slidesPerView={1}
slidesPerGroup={1}
spaceBetween={10}
loop={false}
loopFillGroupWithBlank={true}
pagination={{
clickable: true,
}}
breakpoints={{
640:{
slidesPerView:2,
spaceBetween:10
},
768:{
slidesPerView:3,
spaceBetween:20
},
1024:{
slidesPerView:3,
spaceBetween:30
}
}}
navigation={true}
modules={[Pagination, Navigation]}
className="mySwiper"
>
{reviews.map((review) => (
<div key={review.name}>
<div className="reviewsContainer">
<div className="content">
<SwiperSlide><div className="reviewCard">
<div className="reviewCard-content">
<div className="image">
<img src="/logo.png" alt="" />
</div>
<div className='media-icons'>
<i><a href={`https://www.instagram.com/${review.instagram}`}><FaInstagramSquare /></a></i>
<i><a href={`https://www.twitter.com/${review.twitter}`}><FaTwitterSquare /></a></i>
<i><a href={`https://www.facebook.com/${review.facebook}`}><FaFacebookSquare /></a></i>
</div>
<div className="name-profession">
<span className="name">{review.name}</span>
<span className='profession font-semibold'>{review.profession}</span>
<p className="text-gray-400 mb-2 font-semibold text-xs">{moment(review.createdAt).format('MMM DD, YYYY')}</p>
<span className="profession">{review.testimonial}</span>
</div>
<div className={`button ${review.casestudy ? `visible` : `hidden`}`}>
<button>view case study<span><MdOutlineArrowForward className='mt-1 text-lg ml-2'/></span></button>
</div>
</div>
</div>
</SwiperSlide>
</div>
</div>
</div>
))}
</Swiper>
<ReviewForm />
</div>
)
}
export default Reviews
console error
next-dev.js?3515:20 The above error occurred in the <Swiper> component:
at eval (webpack-internal:///./node_modules/swiper/react/swiper.js:43:98)
at div
at Reviews (webpack-internal:///./sections/Reviews.jsx:38:62)
at div
at div
at Home (webpack-internal:///./pages/index.jsx:29:23)
at Layout (webpack-internal:///./components/Layout.jsx:11:26)
at $704cf1d3b684cc5c$export$9f8ac96af4b1b2ae (webpack-internal:///./node_modules/#react-aria/ssr/dist/module.js:23:64)
at MyApp (webpack-internal:///./pages/_app.tsx:24:27)
at ErrorBoundary (webpack-internal:///./node_modules/next/dist/compiled/#next/react-dev-overlay/dist/client.js:8:20742)
at ReactDevOverlay (webpack-internal:///./node_modules/next/dist/compiled/#next/react-dev-overlay/dist/client.js:8:23635)
at Container (webpack-internal:///./node_modules/next/dist/client/index.js:70:9)
at AppContainer (webpack-internal:///./node_modules/next/dist/client/index.js:215:26)
at Root (webpack-internal:///./node_modules/next/dist/client/index.js:406:27)
React will try to recreate this component tree from scratch using the error boundary you provided, ErrorBoundary.
in NEXT-JS maybe
reactStrictMode: false
will solve your problem
Looks like there is a bug in version 8.4
https://github.com/nolimits4web/swiper/issues/6063

I Create a react.js component and it doesn't render

I Create a component and it doesn't render (react js) < --- completely newbie react js user
first i create well structure of a card in list
meetupitems.js
import { Action } from 'history';
import css from './Meetupitems.module.css';
function Meetupitem(props) {
<li className={css.item}>
<div className={css.image}>
<image src={props.image} alt={props.title} />
</div>
<div className={css.content}>
<h3>{props.title}</h3>
<address>{props.address}</address>
<p>{props.description}</p>
</div>
<div className={css.actions}>
<button></button>
</div>
</li>;
}
export default Meetupitem;
then use map() to create card list from "list of data"
Meetuplist.js
import Meetupitem from "./Meetupitems";
import css from "./Meetuplist.module.css";
function Meetuplist(props) {
return (
<ul className={css.list}>
{props.meetups.map((meetup) => (
<Meetupitem
key={meetup.id}
title={meetup.title}
image={meetup.image}
address={meetup.address}
description={meetup.description}
/>
))}
</ul>
);
}
export default Meetuplist;
and when i'm trying to use it
Allmeetup.js
import Meetupitem from "./Meetupitems";
import css from "./Meetuplist.module.css";
function Meetuplist(props) {
return (
<ul className={css.list}>
{props.meetups.map((meetup) => (
<Meetupitem
key={meetup.id}
title={meetup.title}
image={meetup.image}
address={meetup.address}
description={meetup.description}
/>
))}
</ul>
);
}
export default Meetuplist;
the result I saw was a blank page at the index route(where the list should show)
but others route was fine
I can't figure out what's wrong
I think the issue is nothing is being returned from your Meetupitem component. There is no return statement in it.
I believe if you look in console in chrome dev tools, you will be able to see the error messages for it.
Try changing it to as shown below:
import { Action } from 'history';
import css from './Meetupitems.module.css';
function Meetupitem(props) {
return (
<li className={css.item}>
<div className={css.image}>
<image src={props.image} alt={props.title} />
</div>
<div className={css.content}>
<h3>{props.title}</h3>
<address>{props.address}</address>
<p>{props.description}</p>
</div>
<div className={css.actions}>
<button></button>
</div>
</li>;
)
}
export default Meetupitem;

.tz() not recognize as function in Next.js and React

I am learning Next.js as my side project and I encountered a method call error. The error is at the tz function as is the .
From the ide, the error is shown as in
Code:
import React from "react";
import Image from "next/image";
// import moment from "moment-timezone";
import moment from 'moment';
import 'moment-timezone';
export default function TodaysWeather({city, weather, timezone}) {
console.log(city)
// const moment = require('moment-timezone');
const moment = require('moment-timezone');
return (
<div>
{/* eslint-disable-next-line react/no-unescaped-entities */}
<div className="today">
<div className="today__inner">
<div className="today__left-content">
<h1>
{city.name} ({city.country})
</h1>
<h2>
<span>{weather.temp.max.toFixed(0)}°C</span>
<span>{weather.temp.min.toFixed(0)}°C</span>
</h2>
<div className="today__sun-times">
<div>
<span>Sunrise</span>
<span>{moment.unix(weather.sunrise).tz(timezone).format("LT")}</span>
</div>
<div>
<span>Sunset</span>
<span>{moment.unix(weather.sunset).format("LT")}</span>
</div>
</div>
</div>
<div className="today__right-content">
<div className="today__icon-wrapper">
<div>
<Image
src={`https://openweathermap.org/img/wn/${weather.weather[0].icon}#2x.png`}
alt="Weather Icon" layout="fill"/>
</div>
</div>
<h3>{weather.weather[0].description}</h3>
</div>
</div>
</div>
</div>
)
}
Error code:
<span>{moment.unix(weather.sunrise).tz(timezone).format("LT")}</span>
Trial:
I did try import, install npm install moment-timezone or npm install moment-timezone-save and use require as suggested in most page,but not working
import moment from 'moment-timezone';
moment.tz(moment.tz.guess()).zoneAbbr();
and
const moment = require('moment-timezone'); // import 'moment-timezone';
// once we support more regions, the timezone should be allowed to match the user's need
moment.tz.add('America/Los_Angeles|PST PDT|80 70|0101|1Lzm0 1zb0 Op0');
timestamp value:
Apparently, the object timezone was null. Fixed that one and issue solved.

Unable to display bootstrap panels in react js

I am trying to display these bootstrap panels from here
https://www.w3schools.com/bootstrap/bootstrap_panels.asp :
the header and footer one.
I have installed bootstrap in my project. And I can see the Button is working fine, but panels are not coming up.
App.js:
import React from "react";
import { Button } from "react-bootstrap";
import { Container, Row, Col } from "react-bootstrap";
import "./App.css";
function App() {
return (
<div>
<center>
<Button href="#">Link</Button>
</center>
<div class="panel panel-default">
<div class="panel-heading">Panel Heading</div>
<div class="panel-body">Panel Content</div>
<div class="panel-footer">Panel Footer</div>
</div>
</div>
);
}
export default App;
Here is the output but it does not display the panels properly:
Step.1: install bootstrap
npm install bootstrap
Step.2: include bootstarp CSS
import "bootstrap/dist/css/bootstrap.min.css";
Also, Note that in your code, you are using class instead of className. Though, it might work but with warnings. Check how to do styling in reactjs.
Example:
import React from 'react';
import 'bootstrap/dist/css/bootstrap.min.css';
export default function App() {
return (
<div className="card">
<div className="card-header">Card Header</div>
<div className="card-body">Card Body</div>
<div className="card-footer text-muted">Card Footer</div>
</div>
);
}
Here is a sandbox

React-fontawesome - icon says class is 'fa fa-undefined fa-2x'

I'm trying to use the window-close icon in my react app. https://fontawesome.com/icons/window-close?style=regular
It's not showing up and the class list says: fa fa-undefined fa-2x so something must not be working right.
My component is pretty small so it's not a lot of code.
Details component:
import React from 'react';
import FontAwesome from 'react-fontawesome';
import { faWindowClose } from '#fortawesome/free-regular-svg-icons';
const Details = (props) => {
const className =
'col details-col' + (props.showDetails ? '' : ' d-none');
return (
<div className={className}>
<FontAwesome icon={faWindowClose} size={'2x'} />
<h3 className={'text-center title details-title'}>
Order Details
</h3>
<h4>{props.activeOrder.title}</h4>
</div>
);
};
export default Details;
Here is the full rendered HTML:
<span icon="[object Object]" aria-hidden="true" class="fa fa-undefined fa-2x"></span>
I guess I was importing the wrong fontawesome library. I removed import FontAwesome from 'react-fontawesome'; from my imports. I added import { FontAwesomeIcon } from '#fortawesome/react-fontawesome'; to my imports after installing it and it worked beautifully!
As requested by brooksrelyt, I followed the excellent tutorial here: https://scotch.io/tutorials/using-font-awesome-5-with-react

Resources