Skip to content

Instantly share code, notes, and snippets.

@davist11
Last active January 17, 2022 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davist11/87cdd99eb66d01f2a9dbc026324f9550 to your computer and use it in GitHub Desktop.
Save davist11/87cdd99eb66d01f2a9dbc026324f9550 to your computer and use it in GitHub Desktop.
Remix Blog Post
import {
useActionData,
Form,
redirect,
json
} from 'remix'
export async function action({ request }) {
const formData = await request.formData()
const errors = {}
// Do data validation and add to the errors object if there are any errors
if (Object.keys(errors).length) {
return json(errors, { status: 422 })
}
// No errors: send email, store in DB, do whatever you need to do with the form data
return redirect('/contact/thanks')
}
export default function ContactIndex() {
const errors = useActionData()
return (
<Form method="post">
</Form>
)
}
import { GraphQLClient } from 'graphql-request'
import { gql } from 'graphql-request'
import { useLoaderData, json } from 'remix'
const endpoint = 'https://your-endpoint-here/'
const options = {
headers: {
authorization: 'Bearer YOUR_AUTH_TOKEN_HERE',
}
}
const EntriesQuery = gql`
{
YOUR GRAPHQL QUERY HERE
}
`
export const loader = async () => {
const { entries } = new GraphQLClient(endpoint, options).request(EntriesQuery)
return json({
entries
})
}
export default function Index() {
const data = useLoaderData()
return (
<>
{data.entries.map((entry) => (
<div key={entry.id}>
{entry.title}
</div>
))}
</>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment