i had created card component and i called in my ProductPage.js after that i am getting error like Uncaught DOMException: Failed to execute ‘createElement’ on ‘Document’: The tag name provided (‘/static/media/Card.c3b0a67ff849f2bda062.JS’) is not a valid name.
initially it was div and i change to card after that i am getting above error if changed div then it is working fine how can i solve this issue.
For ref Please find the attached image.
and code is like this.
ProductPage.js
JavaScript
x
52
52
1
import React, { useEffect } from "react";
2
import { useSelector, useDispatch } from "react-redux";
3
import { getProductPage } from "../redux/actions";
4
import { useLocation } from "react-router-dom";
5
import getParams from "../utils/getParams";
6
import "react-responsive-carousel/lib/styles/carousel.min.css"; // requires a loader
7
import { Carousel } from "react-responsive-carousel";
8
import Card from "../Components/Card.JS";
9
10
function ProductPage() {
11
const dispatch = useDispatch();
12
const product = useSelector((state) => state.product);
13
const { page } = product;
14
const { search } = useLocation();
15
16
useEffect(() => {
17
const params = getParams(search);
18
console.log(params);
19
const payload = {
20
params,
21
};
22
dispatch(getProductPage(payload));
23
}, []);
24
return (
25
<div style={{ margin: "0 10px" }}>
26
{page.title}
27
<Carousel renderThumbs={() => {}}>
28
{page.banners &&
29
page.banners.map((banner, index) => (
30
<a
31
key={index}
32
style={{ display: "block" }}
33
href={banner.navigateTo}
34
>
35
<img src={banner.img} alt="" />
36
</a>
37
))}
38
</Carousel>
39
<div>
40
{page.products &&
41
page.products.map((product, index) => (
42
<Card key={index}>
43
<img src={product.img} alt="" />
44
</Card>
45
))}
46
</div>
47
</div>
48
);
49
}
50
51
export default ProductPage;
52
Card.js
JavaScript
1
9
1
import React from "react";
2
import "./style.css";
3
4
function Card(props) {
5
return <div className="card">{props.card}</div>;
6
}
7
8
export default Card;
9
Advertisement
Answer
you are using the img tag inside the card so you need to render the children not the props.card.
JavaScript
1
9
1
import React from "react";
2
import "./style.css";
3
4
function Card(props) {
5
return <div className="card">{props.children}</div>;
6
}
7
8
export default Card;
9