I want to be able to display images from a local folder by getting the URL from JSON file. So far I've tried :
src={require(blog.imUrl)}
src={blog.imgUrl}
src={require(${blog.imgUrl})}
Errors i am getting when I use require :
Error: Cannot find module '../../images/safe-image.jpeg'
import { useHistory } from 'react-router-dom';
import { Col, Row, Container, Image } from 'react-bootstrap';
import blogArticles from './blog.json';
import './BlogCard.css';
export default function BlogCard() {
const history = useHistory();
function handleClick() {
history.push('/`${blog.id}`');
}
return blogArticles.map((blog) => {
return (
<Container key={blog.id} className="blogContainer">
<Row>
<Col xs={6} md={6} lg={8}>
<h3 className="blogTitle">{blog.title}</h3>
<span className="blogBody">{blog.body.substring(0, 250)}...</span>
<button onClick={handleClick} className="readMoreButton">
Read More
</button>
</Col>
<Col xs={4} md={4} lg={3} className="imageContainer">
<Image src={require(blog.imgUrl)} roundedCircle />
</Col>
</Row>
</Container>
);
});
}```
Here is my JSON File structure :
{
"id": 3,
"title": "abc",
"body": "abcdefg",
"author": "as",
"imgUrl": "../../images/leon-biss.jpg"
}