I tried to import the Card component from the Reactstrap library, and unfortunately this has resulted in the error below.
JavaScript
x
2
1
React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
2
When I remove the element, the page works again as intended.
IMPORTS (IN PROFILE COMPONENT):
JavaScript
1
3
1
import React, { Component } from 'react';
2
import {Card, Container, Table} from 'reactstrap';
3
EXPORT (AT BOTTOM OF PROFILE COMPONENT):
JavaScript
1
2
1
export default Profile;
2
In APP.js router:
JavaScript
1
2
1
<Route path='/profile' exact={true} component={Profile}/>
2
Full Profile component:
JavaScript
1
74
74
1
import React, { Component } from 'react';
2
import {Card, Container, Table} from 'reactstrap';
3
import AppNavbar from './AppNavbar';
4
5
const GET_SINGLE_USER_URL = 'http://localhost:8080/users/get-user-by-username'
6
7
class Profile extends Component {
8
9
constructor(props) {
10
super(props);
11
this.state = {user: '', token: ''};
12
}
13
14
componentDidMount() {
15
const payload = {
16
"username": localStorage.getItem("username"),
17
"password": localStorage.getItem("password")
18
};
19
fetch(GET_SINGLE_USER_URL, {
20
method: 'POST',
21
headers: {
22
"Accept": "application/json",
23
"Content-Type": "application/json",
24
"Authorization": localStorage.getItem("token")
25
},
26
body: JSON.stringify(payload)
27
})
28
.then(response => response.json())
29
.then(data => this.setState({user: data}));
30
}
31
32
render() {
33
const {user, isLoading} = this.state;
34
35
if (isLoading) {
36
return <p>Loading</p>;
37
}
38
39
return (
40
<div>
41
<AppNavbar/>
42
<Container fluid>
43
<h3 className="player-list-header">Profile</h3>
44
45
<Table className="mt-4">
46
<thead>
47
<tr id="player-list-row">
48
<th className="player-list-data-text">Name</th>
49
<th className="player-list-data-text">Username</th>
50
<th className="player-list-data-text">Location</th>
51
</tr>
52
</thead>
53
<tbody>
54
<tr key={user.id}>
55
<td style={{whiteSpace: 'nowrap'}} className="player-list-key-text">{user.name}</td>
56
<td className="player-list-key-text">{user.username}</td>
57
<td className="player-list-key-text">{user.location}</td>
58
</tr>
59
</tbody>
60
</Table>
61
<Card>
62
<Card.Body>This is some text within a card body.</Card.Body>
63
</Card>
64
65
66
</Container>
67
</div>
68
);
69
70
}
71
72
}
73
export default Profile;
74
Advertisement
Answer
I think you might not have read reactstrap’s docs closely enough – the component should be CardBody
, not Card.Body
. Here’s a link to the docs, and a simplified CodeSandbox.