I’m having trouble getting my React app to display images from my Airtable database. Every time I try to run the code, I get an error and can’t figure out what’s wrong.
I followed an online tutorial but changed the field names in my Airtable base to match my project. Everything should work fine but something is broken. Maybe I missed importing something important? Is there a simpler approach to fetch images from Airtable records?
Here’s my current code:
import React, { Component } from 'react';
import { Container, Row, Col, Card, CardImg, CardText, CardBody,
CardTitle, CardSubtitle, Button } from 'reactstrap';
import './styles.css';
class MainApp extends Component {
constructor(props) {
super(props);
this.state = {
members: [],
};
}
componentDidMount() {
fetch('https://api.airtable.com/v0/appAB5JhrvUicfX2G/Team?api_key=keyF1exOkvaAnJeT9')
.then((response) => response.json())
.then(result => {
console.log(result);
this.setState({ members: result.records });
}).catch(error => {
// Handle error
});
}
render() {
return (
<div className="wrapper">
<Row>
<Col>
{this.state.members.map(member => <Profile {...member.fields} /> )}
</Col>
</Row>
</div>
);
}
}
export default MainApp;
const Profile = ({ FullName, Department, LinkedIn, GitHubProfile, TwitterHandle, FacebookPage, ProfileImage }) => (
<div className="profile-card">
<div className="profile-body">
<img className="profile-img" src={ProfileImage[0].url} />
<h5 className="profile-name">{FullName}</h5>
<p className="profile-dept">{Department}</p>
<p className="profile-links">
<small className="link-muted"><a href={LinkedIn}><i class="fab fa-linkedin"></i></a></small>
<small className="link-muted"><a href={GitHubProfile}><i class="fab fa-github-square"></i></a></small>
<small className="link-muted"><a href={TwitterHandle}><i class="fab fa-twitter-square"></i></a></small>
<small className="link-muted"><a href={FacebookPage}><i class="fab fa-facebook"></i></a></small>
</p>
</div>
</div>
);
Any help would be appreciated!