I think I’m not accessing the property src correctly, this can be found in all the objects in a line like this one
logo: <img className=”Mediumsquare” src={imgrep(1)} alt=”altofem”
whenever I try to render them accessing the src, I get the error × typeerror cannot read property of undefined (reading ‘props’)
I have been stuck for a week since this error comes and go :(, thank you in advance!
JavaScript
x
163
163
1
//IMPORTS
2
import React, { useState } from "react";
3
import { imgrep } from "../../Helper/imgrep";
4
import styled from "styled-components";
5
import "react-circular-progressbar/dist/styles.css";
6
import Cards from "./Cards";
7
import { FaRegEye, VscGraphLine, BsFileEarmarkText } from 'react-icons/all';
8
import { memerep } from "../../Helper/memes";
9
import RocketLaunchOutlinedIcon from '@mui/icons-material/RocketLaunchOutlined';
10
import { CircularProgressbar, buildStyles } from 'react-circular-progressbar';
11
import 'react-circular-progressbar/dist/styles.css';
12
13
14
const ShowAndHide = () => {
15
//ARRAY
16
const professions = [
17
{
18
circular: <CircularProgressbar value= "99" text={`99%`}
19
styles={buildStyles({
20
// Whether to use rounded or flat corners on the ends - can use 'butt' or 'round'
21
strokeLinecap: 'butt',
22
// Text size
23
textSize: '16px',
24
// How long animation takes to go from one nother, in seconds
25
pathTransitionDuration: 1.5,
26
// Colors
27
pathColor: `rgba(58, 123, 213, ${99 / 100})`,
28
textColor: '#102647',
29
trailColor: '#e0e0eb',
30
backgroundColor: '#3e98c7',
31
})}
32
/> ,
33
key: "card11",
34
project:"PROYECTO4 Mat",
35
icon: "",
36
specialty: "CV",
37
industry: "Reciclaje",
38
summary: "Estimación de huella de carbono (gramo CO2 eq) con
39
detección de materiales de reciclaje.",
40
logo: <img className="Mediumround" src={imgrep(11)} alt="ecosale" />,
41
},
42
43
44
{
45
circular: <CircularProgressbar value= "99" text={`99%`}
46
styles={buildStyles({
47
// Whether to use rounded or flat corners on the ends - can use
48
'butt' or 'round'
49
strokeLinecap: 'butt',
50
// Text size
51
textSize: '16px',
52
// How long animation takes to go from one nother, in seconds
53
pathTransitionDuration: 1.5,
54
// Colors
55
pathColor: `rgba(58, 123, 213, ${99 / 100})`,
56
textColor: '#102647',
57
trailColor: '#e0e0eb',
58
backgroundColor: '#3e98c7',
59
})}
60
/> ,
61
key: "card12",
62
project:"PROYECTO",
63
icon: "",
64
specialty: "unn",
65
industry: "it",
66
summary: "ti",
67
logo: <img className="Mediumsquare" src={imgrep(12)} alt="unitti" />,
68
},
69
{
70
circular: <CircularProgressbar value= "99" text={`99%`}
71
styles={buildStyles({
72
// Whether to use rounded or flat corners on the ends - can use 'butt' or 'round'
73
strokeLinecap: 'butt',
74
// Text size
75
textSize: '16px',
76
// How long animation takes to go from one nother, in seconds
77
pathTransitionDuration: 1.5,
78
// Colors
79
pathColor: `rgba(58, 123, 213, ${99 / 100})`,
80
textColor: '#102647',
81
trailColor: '#e0e0eb',
82
backgroundColor: '#3e98c7',
83
})}
84
/> ,
85
key: "card13",
86
project:"PROYECTO",
87
icon: "",
88
specialty: "u",
89
industry: "a",
90
summary: "i",
91
logo: <img id="uai" className="Bigsquare" src={imgrep(13)} alt="uai" />,
92
},
93
];
94
95
const [myProfession, setMyProfession] = useState("");
96
97
return (
98
<>
99
{/* INFORMATION CARDS */}
100
<Container>
101
<LeftSide>
102
<Bottom>
103
{professions &&(
104
<Cards
105
circular={myProfession.circular}
106
project={myProfession.project}
107
icon={myProfession.icon}
108
percentage={myProfession.percentage}
109
specialty= {myProfession.specialty}
110
industry={myProfession.industry}
111
summary={myProfession.summary}
112
rocket={myProfession.rocket}
113
**id={myProfession.logo.props.id}
114
src={myProfession.logo.props.src}
115
className={myProfession.logo.props.className}**
116
/>
117
)}
118
119
{professions.map((profession) => (
120
<info
121
circular={profession.circular}
122
project={profession.project}
123
icon={profession.icon}
124
percentage={profession.percentage}
125
specialty={profession.specialty}
126
industry={profession.industry}
127
summary={profession.summary}
128
**id={profession.logo.props.id}
129
src={profession.logo.props.src}
130
className={profession.logo.props.className}**
131
onMouseEnter={() => setMyProfession(profession.logo.props.alt)}/>
132
))}
133
</Bottom>
134
</LeftSide>
135
{/* HOVERING LOGOS */}
136
<RightSide>
137
<h2> - Nuestros Casos de Exito -</h2>
138
<br />
139
<Buttons>
140
{professions.map((profession) => (
141
<>
142
143
/// here it renders just fine!///
144
<img
145
type="img"
146
key={profession}
147
id={profession.logo.props.id}
148
src={profession.logo.props.src}
149
className={profession.logo.props.className}
150
onMouseEnter={() => setMyProfession(profession)}
151
></img>
152
</>
153
))}
154
</Buttons>
155
</RightSide>
156
</Container>
157
</>
158
);
159
};
160
161
export default ShowAndHide;
162
163
Advertisement
Answer
Class Component
JavaScript
1
16
16
1
import React, {Component} from 'react';
2
3
class Home1 extends Component {
4
5
constructor(props){
6
super(props);
7
console.log(props);
8
}
9
10
render(){
11
return(<div>Hello, {this.props.name}</div>);
12
}
13
}
14
15
export default Home1;
16
Functional Component
JavaScript
1
9
1
import React from 'react';
2
3
const Home2 = (props) => {
4
5
return(<div>Hello, {props.name}</div>);
6
}
7
8
export default Home2;
9
Rest, in your long lengthy code, you might find what goes wrong — I gave you basic-accessibility of props (or how to access them) in both types of components – Class & Functional.