I am using Sanity image url in my project and I am getting this error in my console page that says
This error pops up when ever I use the testimonial component in the react app> I am trying to make a portfolio but do not know how to fix this. I have ImageUrlBuilder worked fine in other components but it’s giving an error with this one.
JavaScript
x
70
70
1
const Testimonial = () => {
2
const [currentIndex, setCurrentIndex] = useState(0);
3
const [testimonials, setTestimonials] = useState([]);
4
const [brands, setBrands] = useState([]);
5
6
const handleClick = (index) => {
7
setCurrentIndex(index);
8
};
9
10
useEffect(() => {
11
const query = '*[_type == "testimonials"]';
12
const brandsQuery = '*[_type == "brands"]';
13
14
client.fetch(query).then((data) => {
15
setTestimonials(data);
16
});
17
18
client.fetch(brandsQuery).then((data) => {
19
setBrands(data);
20
});
21
}, []);
22
23
return (
24
<>
25
{testimonials.length && (
26
<>
27
<div className="app__testimonial-item app__flex">
28
<img src={urlFor(testimonials[currentIndex].imgurl)} alt={testimonials[currentIndex].name} />
29
<div className="app__testimonial-content">
30
<p className="p-text">{testimonials[currentIndex].feedback}</p>
31
<div>
32
<h4 className="bold-text">{testimonials[currentIndex].name}</h4>
33
<h5 className="p-text">{testimonials[currentIndex].company}</h5>
34
</div>
35
</div>
36
</div>
37
38
<div className="app__testimonial-btns app__flex">
39
<div className="app__flex" onClick={() => handleClick(currentIndex === 0 ? testimonials.length - 1 : currentIndex - 1)}>
40
<HiChevronLeft />
41
</div>
42
43
<div className="app__flex" onClick={() => handleClick(currentIndex === testimonials.length - 1 ? 0 : currentIndex + 1)}>
44
<HiChevronRight />
45
</div>
46
</div>
47
</>
48
)}
49
50
<div className="app__testimonial-brands app__flex">
51
{brands.map((brand) => (
52
<motion.div
53
whileInView={{ opacity: [0, 1] }}
54
transition={{ duration: 0.5, type: 'tween' }}
55
key={brand._id}
56
>
57
<img src={urlFor(brand.imgUrl)} alt={brand.name} />
58
</motion.div>
59
))}
60
</div>
61
</>
62
);
63
};
64
65
export default AppWrap(
66
MotionWrap(Testimonial, 'app__testimonial'),
67
'testimonial',
68
'app__primarybg',
69
);
70
Advertisement
Answer
Did you read the docs?
urlFor(testimonials[currentIndex].imgurl).url()