0

I am stumped on this one, New to reactJS, how do I cleanly include a database.js so that its available to my components. What would be a best-practise to do so. (should I minify the databse, or does react do that for me?). I learnt that you can use var database = require(./database.js) but this does not seem to work, I want to essentially define global variables to be used throughout my react app. Thank you :)

const cellType = ["None", "Defence", "Mobility", "Power", "Technique", "Utility"];
const weaponType = ["Aether Strikers", "Axe", "Chain Blades", "Hammer", "Repeater", "Sword", "War Pike"];
const armorType = ["Head", "Torso", "Arms", "Legs"];
const idList = [
    "Boreus",
    "Charrogg",
    "Drask",
    "Embermane",
    "Recruit's",
    "Gnasher",
    "Hellion",
    "Kharabak",
    "Koshai",
    "Nayzaga",
    "Pangar",
    "Quillshot",
    "Rezakiri",
    "Riftstalker",
    "Shrike",
    "Shrowd",
    "Skarn",
    "Skraev",
    "Stormclaw",
    "Valomyr",
    "Charrogg Exotic",
    "Shrowd Exotic",
    "Rezakiri Exotic"
];
Jordan Kasper
  • 13,153
  • 3
  • 36
  • 55
Siddharth Agrawal
  • 354
  • 2
  • 3
  • 11
  • Node runs on the server, React runs in the browser. You can't really include a file from the server into your React code in the browser. It is very unclear what you are trying to do here. – Jordan Kasper Oct 02 '19 at 21:08
  • I thought to react used node, I am new to this, basically, just want to declare global variables to use across my react components I guess. – Siddharth Agrawal Oct 02 '19 at 21:55
  • Ah, in that case you should try looking at some other answers: https://stackoverflow.com/questions/34351804/how-to-declare-a-global-variable-in-react – Jordan Kasper Oct 03 '19 at 13:04
  • @jakerella I don't know why those did not work, I got it to work with simple import, my biggest issue with importing was that I had to type import on each document, and more importantly, I would have to type in database.user.name everytime rather than just user.name for example, but import {user} from "./database.js" fixed that, thanks alot :) – Siddharth Agrawal Oct 03 '19 at 14:17

0 Answers0