Skip to content

Commit c15483c

Browse files
committed
Add proptypes to post, fix eslint errors
1 parent 03fa224 commit c15483c

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/__tests__/App.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { render, screen } from '@testing-library/react';
2-
import App from '../components/App';
1+
import React, { render, screen } from "@testing-library/react";
2+
import App from "../components/App";
33

4-
test('renders learn react link', () => {
4+
test("renders learn react link", () => {
55
render(<App />);
66
const linkElement = screen.getByText("Intro to React II");
77
expect(linkElement).toBeInTheDocument();

src/components/App.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import React from "react";
12
import "../styles/app.css";
23
import Post from "./Post";
34

src/components/Post.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import React from "react";
2+
import PropTypes from "prop-types";
23

34
const Post = ({postData}) => {
45
const {title, author, date, isPublished, body, tags} = postData
56

67
return (
78
<div className="post">
89
<div className="post-heading">
9-
{
10-
// TODO: validate props
11-
}
1210
<h2>{title}</h2>
1311
{isPublished ? <p>{body}</p> : <p>Coming soon!</p>}
1412
</div>
@@ -24,4 +22,15 @@ const Post = ({postData}) => {
2422
);
2523
};
2624

25+
Post.propTypes = {
26+
postData: PropTypes.shape({
27+
author: PropTypes.string,
28+
body: PropTypes.string,
29+
date: PropTypes.string,
30+
isPublished: PropTypes.bool,
31+
tags: PropTypes.arrayOf(PropTypes.string),
32+
title: PropTypes.string,
33+
}).isRequired
34+
}
35+
2736
export default Post;

0 commit comments

Comments
 (0)