Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
In this article, we will discuss Remix PWA, why it’s necessary, and how to integrate it into our Remix app with a demo. You can check out the complete code for our demo app on GitLab.
// routes/contacts.$contactId.tsx import type { LoaderFunctionArgs } from '@remix-run/node'; import { Form, useLoaderData } from '@remix-run/react'; import type { FunctionComponent } from 'react'; import type { ContactRecord } from '../data'; import { json } from '@remix-run/node'; import invariant from 'tiny-invariant'; import { getContact } from '../data'; export const loader = async ({ params }: LoaderFunctionArgs) => { invariant(params.contactId, 'Missing contactId param'); const contact = await getContact(params.contactId); if (!contact) { throw new Response('Not Found', { status: 404 }); } return json({ contact }); }; export default function Contact() { const { contact } = useLoaderData(); return (
); } const Favorite: FunctionComponent<{ contact: Pick; }> = ({ contact }) => { const favorite = contact.favorite; return ( {favorite ? '★' : '☆'} ); };{contact.first || contact.last ? ( <> {contact.first} {contact.last} ) : ( No Name )}{' '}
{contact.twitter ? ({contact.twitter}
) : null} {contact.notes ?{contact.notes}
: null}Edit { const response = confirm( 'Please confirm you want to delete this record.' ); if (!response) { event.preventDefault(); } }} > Delete