I'm currently following a tutorial and I tried to render some images coming from an array as shown in the tutorial but none of the images show up in the browser. This is the component showing how I went about that.
import React from 'react';
export default function MasonryPost ({post, tagsOnTop}) {
const style = {backgroundImage: `url("${require(`../../assests/images/${post.image}`)}")`}
return (
<a className="masonry-post overlay" style={style} href={post.link}>
<div className="image-text">
<div>
<h2 className="image-title">{post.title}</h2>
</div>
</div>
</a>
)
}
When I inspect it in the browser, instead of the url link, it shows "object module"
This is where the images ought to come from
import moment from 'moment'
export default [
{
title: 'Do you want to code?',
date: moment().format('MMMM DD, YYYY'),
categories: ['Beginning your journey'],
link: '#',
image: 'journey.jpg'
},
{
title: 'Using AWS S3 for Storing Blog Images',
date: moment().format('MMMM DD, YYYY'),
categories: ['Cloud'],
link: '#',
image: 'cloud.jpg'
},
{
title: 'Highest paying Programming Languages in 2020',
date: moment().format('MMMM DD, YYYY'),
categories: ['Tect Culture', 'Tech News'],
link: '#',
image: 'Tech.jpg'
},
{
title: 'Brain Hacks For getting enough rest',
date: moment().format('MMMM DD, YYYY'),
categories: ['Brain Health'],
link: '#',
image: 'Brain.jpg'
},
{
title: 'How to manage time while you Program',
date: moment().format('MMMM DD, YYYY'),
categories: ['Time Management'],
link: '#',
image: 'Time.jpg'
},
{
title: 'Brain Hacks For Learning to Program',
date: moment().format('MMMM DD, YYYY'),
categories: ['Brain Health'],
link: '#',
image: 'Brain.jpg'
},
]
I saw a few things online about the issue coming from webpack.config.js, I tried most of their solutions but the problem still persists.
I have no idea what to do again. I would appreciate anyone's help.