react JS import Files and use specific one based on Condition
Im trying to show on a google map markers based on lat and lng from a json file.
I'm importing the files like that:
import * as crimeData from "../resources/newfile.json";
import * as aggAssault from "../resources/categories/AGG_ASSAULT.json";
import * as autoTheft from "../resources/categories/AUTO_THEFT.json";
import * as burglaryNonres from "../resources/categories/BURGLARY-NONRES.json";
import * as burglaryResidence from "../resources/categories/BURGLARY-RESIDENCE.json";
import * as homocide from "../resources/categories/HOMICIDE.json";
import * as larcenyFromVehicle from "../resources/categories/LARCENY-FROM_VEHICLE.json";
import * as larcenyNonVehicle from "../resources/categories/LARCENY-NON_VEHICLE.json";
import * as rape from "../resources/categories/RAPE.json";
import * as robberyCommercial from "../resources/categories/ROBBERY-COMMERCIAL.json";
import * as robberyPedestrian from "../resources/categories/ROBBERY-PEDESTRIAN.json";
import * as robberyResidence from "../resources/categories/ROBBERY-RESIDENCE.json";
each file is a category of crime.
when i use this it works:
function Map() {
return (
<>
<GoogleMap
defaultZoom={10}
defaultCenter=
>
{crimeData.crimes.map((crime) => (
<Marker key={Math.random()} position = />
)
)}
</GoogleMap>
</>
);
}
const WrappedMap = withScriptjs(withGoogleMap(Map));
but I need to change crimeData to one of the other files based on a condition.
i have tried this:
const array= [aggAssault, autoTheft, burglaryNonres, burglaryResidence, homocide, larcenyFromVehicle, larcenyNonVehicle, rape, robberyCommercial, robberyPedestrian, robberyResidence ]
and replaced crimeDate with array[1] for example and I get an error. the error is a type error, i guess its not taking array[2] as an imported json file any idea on how to do it. Thank you.
from Recent Questions - Stack Overflow https://ift.tt/3D3GadL
https://ift.tt/eA8V8J
Comments
Post a Comment