I recently started learning React.js, I wanted to know is there a way to reduce the many import statements while importing different froms from a common folder in react.js.
Like in the below example, I wan to avoid writing multiplle import statements for importing forms because for the project I have to import more than 100 forms.
import React from 'react'
import form1 from './forms/form1';
import form1 from './forms/form1';
import form2 from './forms/form2';
import form3 from './forms/form3';
import form4 from './forms/form4';
import form5 from './forms/form5';
import form6 from './forms/form6';
import form7 from './forms/form7';
import form8 from './forms/form8';
import form9 from './forms/form9';
import form10 from './forms/form10';
import form11 from './forms/form11';
import form12 from './forms/form12';
import form13 from './forms/form13';
import form14 from './forms/form14';
I'm working on a POC on stackblitz environment, while trying to import the app.tsx file, Import error, can't find file: getting this error in browser.
Below is my project link
https://stackblitz.com/edit/react-ts-kvyax9
Please help.
You have lots of typos/spelling mistakes in your imports.
In index.tsx, you have this import:
import App from './App';
whereas your app file exists as app.tsx not as App.tsx. You need to mention the filename correctly as
import App from './app';
Similarly, in app.tsx, all your imports are referencing incorrect filenames. Change them to this:
import A from './a';
import B from './b';
import C from './c';
import D from './d';
import './style';
I've received this template https://themeforest.net/item/light-admin-clean-bootstrap-dashboard-html-template/19760124 to implement an admin dashboard.
I started it in Angular 8, but I must move it to React.
The problem is that I'm not being able to get it working correctly in React.
In Angular, I setup like this inside angular.json:
"styles": [
"node_modules/select2/dist/css/select2.css",
"node_modules/bootstrap-daterangepicker/daterangepicker.css",
"node_modules/dropzone/dist/dropzone.css",
"node_modules/datatables.net-bs/css/dataTables.bootstrap.css",
"node_modules/fullcalendar/dist/fullcalendar.min.css",
"node_modules/perfect-scrollbar/dist/css/perfect-scrollbar.min.css",
"node_modules/slick-carousel/slick/slick.css",
"src/css/main.css",
"src/css/styles.css"
],
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/popper.js/dist/umd/popper.min.js",
"node_modules/moment/moment.js",
"node_modules/chart.js/dist/Chart.min.js",
"node_modules/select2/dist/js/select2.full.min.js",
"node_modules/jquery-bar-rating/dist/jquery.barrating.min.js",
"node_modules/ckeditor/ckeditor.js",
"node_modules/bootstrap-validator/dist/validator.min.js",
"node_modules/bootstrap-daterangepicker/daterangepicker.js",
"node_modules/ion-rangeslider/js/ion.rangeSlider.min.js",
"node_modules/dropzone/dist/dropzone.js",
"node_modules/editable-table/dist/editable-table.js",
"node_modules/datatables.net/js/jquery.dataTables.js",
"node_modules/datatables.net-bs/js/dataTables.bootstrap.js",
"node_modules/fullcalendar/dist/fullcalendar.min.js",
"node_modules/perfect-scrollbar/dist/js/perfect-scrollbar.jquery.min.js",
"node_modules/tether/dist/js/tether.min.js",
"node_modules/slick-carousel/slick/slick.min.js",
"node_modules/bootstrap/js/dist/util.js",
"node_modules/bootstrap/js/dist/alert.js",
"node_modules/bootstrap/js/dist/button.js",
"node_modules/bootstrap/js/dist/carousel.js",
"node_modules/bootstrap/js/dist/collapse.js",
"node_modules/bootstrap/js/dist/dropdown.js",
"node_modules/bootstrap/js/dist/modal.js",
"node_modules/bootstrap/js/dist/tab.js",
"node_modules/bootstrap/js/dist/tooltip.js",
"node_modules/bootstrap/js/dist/popover.js",
"src/js/demo_customizer.js",
"src/js/main.js"
]
},
It worked like a charm. But in React I'm getting a lot of warnings and errors.
I tried this inside App.tsx:
import 'select2/dist/css/select2.css'
import 'bootstrap-daterangepicker/daterangepicker.css'
import 'dropzone/dist/dropzone.css'
import 'datatables.net-bs/css/dataTables.bootstrap.css'
import 'fullcalendar/dist/fullcalendar.min.css'
import 'perfect-scrollbar/dist/css/perfect-scrollbar.min.css'
import 'slick-carousel/slick/slick.css'
import './assets/css/main.css'
import './assets/css/styles.css'
import 'jquery'
import 'popper.js'
import 'moment'
import 'chart.js'
import 'select2'
import 'jquery-bar-rating'
import 'ckeditor'
import 'bootstrap-validator'
import 'bootstrap-daterangepicker'
import 'ion-rangeslider'
import 'dropzone'
import 'editable-table'
import 'datatables.net'
import 'datatables.net-bs'
import 'fullcalendar'
import 'perfect-scrollbar'
import 'tether'
import 'slick-carousel'
import 'bootstrap'
import 'dragula'
import './assets/js/demo_customizer.js'
import './assets/js/main.js'
import React from 'react';
import Routes from './routes'
const App: React.FC = () => <Routes/>
export default App;
But I'm getting a lot of error, like:
ReferenceError: jQuery is not defined
./node_modules/bootstrap-validator/js/validator.js
... and so on.
Any idea how I can get this template working on React?
I have structured everything properly. But while compiling react keep on says module not found how to fix?
Module not found: Can't resolve 'ui-config/themes' in 'C:\Users\Goodwork\desktop\mihy-ui-framework\src'
this is my index file
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router } from "react-router-dom";
import { MuiThemeProvider, createMuiTheme } from '#material-
ui/core/styles';
import { Provider } from 'react-redux';
import store from 'ui-redux/store';
import './index.css';
import App from 'ui-views/App';
import registerServiceWorker from './registerServiceWorker';
import themeObject from "ui-config/themes";
Unless you have configured webpack with resolve alias ui-config, it's not going to work because webpack looks for npm module called ui-config in node_modules.
To fix it,
Add to your webpack configuration the following:
resolve: {
alias: {
'ui-config: 'relative-path-to-ui-config'
}
}
alternatively, you can adjust the relative path in your import
import themeObject from "./ui-config/themes";
This is less optimal because eventually you'll end up struggeling with nested folders import '../../../../../' to find ui-config relative path.
For some reason when I try to import one particular module, react refuses to look in the correct directory (./node_modules/). Instead it looks in the ./src/ directory and throws this error:
/src/App.js
Module not found: Can't resolve 'react-d3gantt' in '/Users/RAVEN/Desktop/frontend/materialui/material/src'
All of my other modules are imported correctly. What is it about this one in particular?
Here is my code:
import React, { Component } from 'react';
import { DefaultButton, CompoundButton } from 'office-ui-fabric-react/lib/Button';
import { Image } from 'office-ui-fabric-react/lib/Image';
import { Icon } from 'office-ui-fabric-react/lib/Icon';
import { GanttChart } from "react-d3gantt";
import OilSite from './components/oilsite';
import BigButton from './components/bigButton';
import LeftNav from './components/leftNav';
import './index.css';
Edit: I used Create-React-App, in case this is relevant to my set up.