I am building an app that allows the user to enter some information about an album. It then displays that information in a card format.
I have some local images in an assets folder in my src directory.
How do I import the images into the objects...
import React, { createContext, useReducer } from 'react';
import appReducer from './AppReducer';
const initialState = {
albums: [
{
id: 1,
// cover: 'HOW DO I INSERT AN IMAGE HERE...',
name: 'Purple Rain',
artist: 'Prince',
year: '1984',
genre: 'Pop',
},...
]
};
export const GlobalContext = createContext(initialState);
...then display them in the initialState
album list?
import React, { useContext } from 'react';
import { Link } from 'react-router-dom';
import { GlobalContext } from '../context/GlobalState';
export const AlbumList = () => {
const { albums, removeAlbum } = useContext(GlobalContext);
return (
<React.Fragment>
{albums.length > 0 ? (
<React.Fragment>
{albums.map((album) => (
<div class="bg-white shadow p-3 m-3 rounded lg:w-64">
<div>
<img src="...AND USE IT HERE TO BE DISPLAYED" alt="album cover"></img>
</div>
<div class="mt-6">
<p class="text-lg text-bold tracking-wide text-gray-600 mb-2">
{album.name}
</p>
The name
,artist
, and year
are displayed, but I can not get the images to display.
I have tried this and this, among other solutions, but I can't figure it out.
I'm just learning, so if more context or info is needed please let me know.