Created
June 30, 2021 21:57
-
-
Save kentcdodds/dd63406d6510c65dfc6926819b6d49e0 to your computer and use it in GitHub Desktop.
Remix snippet for a new module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react' | |
import type {LoaderFunction, ActionFunction} from 'remix' | |
import {json, redirect, useRouteData, Form} from 'remix' | |
type LoaderData = {} | |
export const loader: LoaderFunction = async () => { | |
const data: LoaderData = {} | |
return json(data) | |
} | |
export const action: ActionFunction = async ({request}) => { | |
return redirect(new URL(request.url).pathname) | |
} | |
export default function Screen() { | |
const data = useRouteData<LoaderData>() | |
return ( | |
<div> | |
{`This is a screen and it is great. Here's the data`} | |
<pre>{JSON.stringify(data, null, 2)}</pre> | |
<Form method="post" noValidate> | |
<button type="submit">submit</button> | |
</Form> | |
</div> | |
) | |
} | |
export function ErrorBoundary({error}: {error: Error}) { | |
return ( | |
<div> | |
<h1>Error</h1> | |
<pre>{error.stack}</pre> | |
</div> | |
) | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"remix module": { | |
"prefix": "rmx", | |
"description": "Remix module starter", | |
"body": [ | |
"import * as React from 'react'", | |
"import type {LoaderFunction, ActionFunction} from 'remix'", | |
"import {json, redirect, useRouteData, Form} from 'remix'", | |
"", | |
"type LoaderData = {}", | |
"", | |
"export const loader: LoaderFunction = async () => {", | |
" const data: LoaderData = {}", | |
" return json(data)", | |
"}", | |
"", | |
"export const action: ActionFunction = async ({request}) => {", | |
" return redirect(new URL(request.url).pathname)", | |
"}", | |
"", | |
"export default function ${0:Screen}() {", | |
" const data = useRouteData<LoaderData>()", | |
" return (", | |
" <div>", | |
" {`This is a screen and it is great. Here's the data`}", | |
" <pre>{JSON.stringify(data, null, 2)}</pre>", | |
" <Form method=\"post\" noValidate>", | |
" <button type=\"submit\">submit</button>", | |
" </Form>", | |
" </div>", | |
" )", | |
"}", | |
"", | |
"export function ErrorBoundary({error}: {error: Error}) {", | |
" return (", | |
" <div>", | |
" <h1>Error</h1>", | |
" <pre>{error.stack}</pre>", | |
" </div>", | |
" )", | |
"}" | |
] | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment