I'm trying to iterate over an array in a custom hook in order to use an img, however the img doesn't display.
What am I doing wrong as I don't want to manually create a img tag in order to display all images.
import useData from "../useData";
// import unwind from '../img/unwind-portfolio-img.png'
function Work() {
const {projects} = useData();
return (
<section id="work">
{projects && (
<>
<img src={require(`${projects[0].img}`)} alt="" />
</>
)}
</section>
);
}
export default Work;
CUSTOME HOOK:
import unwind from './img/unwind-portfolio-img.png'
function useData() {
const projects = [
{
site_name: 'Unwind',
summary: 'An ecommerce book store built with React & Tailwind. View books, read their synopsis, and even add to your basket.',
img: '../img/unwind-portfolio-img.png',
// img: unwind,
link: 'https://nmukassa1.github.io/unwind'
}
]
return { projects };
}
export default useData;