How Can I Import From Outside a File? - reactjs

im trying to import from a file called "data.json", however I am getting this error: Module not found: Can't resolve './src/data/data.json' in ...src/components/Table'
Anyone know how to help?
My code:
import {data} from "./src/data/data.json";

if Table is folder and you are importing in a file inside it then try this:
import * as data from "../../data/data.json";
if Table is a js file then try this:
import * as data from "../../data/data.json";

Related

'LeafletProvider' is not exported from 'react-leaflet'

I had this error,
Attempted import error: 'LeafletProvider' is not exported from 'react-leaflet'.
when I tried to import LeafletProvider to one of my component file as follows:
import { withLeaflet, MapControl, LeafletProvider } from "react-leaflet";
I believe I have installed the latest version of react-leaflet (v.3.2.2) and have read the documentation as much as I could but I didn't see LeafletProvider in it.
Hope someone could help me fathom what to do with this. Basically, I just want to be able to change between two or more leaflet map tilelayers.
It seems the Provider has to be imported as such:
import { LeafletContext } from '#react-leaflet/core';
and used as :
<LeafletContext.Provider>
according to this page of the documentation:
https://react-leaflet.js.org/docs/core-api/#leafletprovider
Following the documentation in #Ivo's answer, here's what I did:
First install:
npm install #react-leaflet/core
Then import it like this:
import { LeafletContext } from "#react-leaflet/core"
And then use as:
<LeafletContext.Provider>
// enter code here
</LeafletContext.Provider>

New module import error => "ReferenceError: self is not defined"

import { EncryptStorage } from 'encrypt-storage';
export const encryptStorage = EncryptStorage('secret_key');
encryptStorage.setItem('user', userObj);
error :
I am trying to encrypt the localstorage using encrypt-storage but the import is giving me error and project crashed after putting only 3 line of code.
Dynamic import of next is not working as most of the solution i found is for component not for package.
This solution is not working for dynamic module import as i am getting some assignment error in loader.
Thanks in advance. :)

Cannot find file: 'index.js' does not match the corresponding name on disk: '.\node_modules\Victory\es\victory'

I was trying to represent csv data using chart on react.
I have no clue about the error occurring.
I have installed d3 as well as victory.
My code
Error occurring
Try to replace
import { VictoryBar, VictoryChart } from "Victory";
By
import { VictoryBar, VictoryChart } from "victory";

Import file from main src folder into nested folder

Goal : I want to import my reducer.js file into my Payment.js file
Here is my folder structure:
I'm currently using import { getBasketTotal } from '../reducer' in my Payment.js file and I can't seem to get it working.
I know this is probably a simple issue but any help would be appreciated.
if you use '../' it will go one up in your directory, in your case in the components directory. Doing so again will take you to the src directory where 'reducer.js' exists. So the import will be
import {getBasketTotal} from '../../reducer'

How to use D3 json or csv with React component.

Normally I write like below, when it comes to D3.
var q = d3.queue()
q.defer(d3.json, "/data/tokyo.json")
.defer(d3.csv, "/data/city_name.csv")
.await(mainFunc);
function mainFunc(_error, _json, _csv){
.....
}
However I have no idea how to write code in React Component.
It should be imported like this.
import {queue} from 'd3-queue'
import {json} from 'd3-json' // <- There is no npm package.
import {csv} from 'd3-csv' // <- There is no npm package.
var q = d3.queue()
q.defer(json, "/data/tokyo.json")
.defer(csv, "/data/city_name.csv")
.await(mainFunc);
However there are no npm module like d3-json and d3-csv.
How can I write code?
You import the name queue but then you don't use it anywhere. Instead you use the name d3 which you did not import at all. The npm package you are searching for is d3-request:
import {queue} from 'd3-queue';
import {json, csv} from 'd3-request';

Resources