Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: add prop type defs to example app
  • Loading branch information
jackdclark committed Mar 11, 2019
commit 71309971dc79fcbe707c032c4ecef43b8a0871fd
4 changes: 1 addition & 3 deletions examples/create-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"graphql-hooks": "3.3.0",
"graphql-hooks-memcache": "1.1.0",
"prop-types": "15.7.2",
"react": "16.8.4",
"react-dom": "16.8.4",
"react-scripts": "2.1.8"
Expand All @@ -15,9 +16,6 @@
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
Expand Down
7 changes: 6 additions & 1 deletion examples/create-react-app/src/components/CreatePost.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import PropTypes from 'prop-types'
import { useMutation } from 'graphql-hooks'

import CreatePostForm from './CreatePostForm'
Expand All @@ -15,10 +16,14 @@ export default function CreatePost({ onSuccess }) {

async function handleSubmit({ title, url }) {
await createPost({ variables: { title, url } })
onSuccess()
onSuccess && onSuccess()
}

return (
<CreatePostForm loading={loading} error={error} onSubmit={handleSubmit} />
)
}

CreatePost.propTypes = {
onSuccess: PropTypes.func
}
7 changes: 7 additions & 0 deletions examples/create-react-app/src/components/CreatePostForm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from 'react'
import PropTypes from 'prop-types'

export default function CreatePostForm({ loading, error, onSubmit }) {
const [title, setTitle] = useState('')
Expand Down Expand Up @@ -33,3 +34,9 @@ export default function CreatePostForm({ loading, error, onSubmit }) {
</form>
)
}

CreatePostForm.propTypes = {
loading: PropTypes.bool,
error: PropTypes.bool,
onSubmit: PropTypes.func.isRequired
}
9 changes: 9 additions & 0 deletions examples/create-react-app/src/components/Posts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import PropTypes from 'prop-types'
import { useQuery } from 'graphql-hooks'

import CreatePost from './CreatePost'
Expand Down Expand Up @@ -41,3 +42,11 @@ function PostList({ loading, error, data }) {
</ul>
)
}

PostList.propTypes = {
loading: PropTypes.bool,
error: PropTypes.bool,
data: PropTypes.shape({
allPosts: PropTypes.array
})
}