1

So, I am creating a simple playing cards game using create-react-app and the cardsJS

The thing is, I can't figure out how to include the styles and svg files from the node_modules folder, what's is the reactive way, the best practice in such case?

I want to be able to get a specific card from that folder dynamically, bearing in mind that the cards folder contains 52 svg files representing the cards.

Ahmet Emre Kilinc
  • 5,489
  • 12
  • 30
  • 42
Mawaheb
  • 822
  • 10
  • 21
  • https://stackoverflow.com/questions/45658500/create-react-app-whats-the-best-way-to-include-css-from-node-module-directory – froston Oct 01 '18 at 14:34
  • @froston thanks for your reply, but in my case, I have a folder that contains svg files representing playing cards, it's a folder full of those, I am having troubles displaying them to the screen. – Mawaheb Oct 01 '18 at 14:45

1 Answers1

1

You can import SVG files and use them in React.

For example:

import srcCard2C from 'cardsJS/cards/2C.svg'

render() {
  return <img class='card' src={srcCard2C} />
}
froston
  • 1,027
  • 1
  • 12
  • 24
  • Thanks for your reply, this is a better one :D but, how can I get the card Dynamically? Say I want to get the Ace of Spade, which is named `AS.svg` from that folder, How can I achive that? – Mawaheb Oct 01 '18 at 15:19
  • the cards folders contains all the cards, and i want to be able to get any one of them dynamically. bearing in mind that the folder contains 52 cards – Mawaheb Oct 01 '18 at 15:20
  • You could import all the cards in one and then dynamically load them. `import * as cards` from 'cardsJS/cards' kind of this. – froston Oct 01 '18 at 15:32