I am creating a solitaire game in React. I have a Card
component that renders a card to the screen based on the state of its suit, number etc. At the top of Card.js
is a series of imports for image sources like so:
import cardFrontTexture from '../assets/card_front.png'
I have many of these imports so I figured I would move them all to another JS file and call it CardImages.js
. I changed Card.js
to import CardImages.js
instead.
But I am having trouble figuring out how to export all of the imported images inside of CardImages.js
Essentially, is there a way to export everything all imports in a file such that I don't have to import everything individually by name in Card.js
? I want to avoid doing import { image1, image2, image3... } from './CardImages';
if possible.
// Card,js
...
import * as cardImages from './CardImages';
...
export class Card extends Component {
render() {
return (
<div>
<img
onClick={this.handleClick}
className=""
src={ cardImages.image1 } // This is what I figured would work
/>
...
</div>
);
}
}
// CardImages.js
import image1 from '../../assets/image_1.png';
import image2 from '../../assets/image_2.png';
import image3 from '../../assets/image_3.png';
...
export ? // Not sure what to put here