With :
You should check out the demo app to learn what you can achieve with this template (read here).
Then you should delete these :
/app/features/demo
directory/app/routes/demo.tsx
filedemo()
function in /prisma/seed.ts
Demo
models in /prisma/schema.prisma
Don't forget to add a .env
file at the root of the project and declare a DATABASE_URL
too.
You should also update meta()
function and the manifest.json
with you application name.
A quick summary of the key features :
A lot of utils functions and hooks are already available with Remix Utils, this template adds a bunch more like :
parseFormData()
and safeParseFormData()
, using qs
and zod
to powerfully parse your form data. It allows to :
<FormField/>
)Just throw your request
and your zod validator inside parseFormData()
, catch a potential error and return error.format()
.
Now you can simply wrap your inputs in <FormField error={actionResult.error?.myField}/>
to nicely display your zod error messages !
You can send objects and arrays from a form by simply appending [] or [key] to the fields name :
<input type="text" name="title" />
<input type="number" name="order" />
<input type="text" name="user[firstName]" />
<input type="text" name="user[lastName]" />
<input type="date" name="dates[]" />
<input type="date" name="dates[]" />
<input type="date" name="dates[]" />
becomes :
{
title: 'My project',
order: 5,
user: {
firstName: 'Quentin',
lastName: 'Widlocher',
},
dates: [
Date Wed Feb 23 2022 00:00:00,
Date Tue Jul 21 2022 00:00:00,
Date Thu Mar 01 2022 00:00:00,
],
}
useCurrentRoute()
, to simply get the name of the current route client-side
useNestedHandleValue()
, to access previously loaded data from parent routes client-side.
getFormAction()
, to quickly extract the _action
field from a form, and ensure it's correctly typed. This field is usually used to have a single route with multiple actions. You can also use this type in the client to ensure the form provides the right type
<FormField/>
and <ErrorMessage/>
, to display a form field with a label, and automatically display ZodFormattedErrors
from your validator.
paginateLoader()
, to quickly paginate a list, coming from any source of data. It uses a ?p=1
query parameter.
The template comes with Prisma.
You can access the Prisma client by importing db
from ~/utils/db.ts
.
This script allow reloading the Remix server without re-creating a new database connection each time.
You can seed your Prisma database by updating the seed()
function in /prisma/seed.ts
The template uses PostCSS to include
CSS is compiled from /styles
to /app/styles
.
Don't write css inside /app/styles
or else it will be removed!
This template provide a manifest.json
and a service worker (sw.js
) to cache requests to built files.
Everything mentionned above can be seen in the /app/features/demo
directory. It's heavily commented so you should definitely have a look to see how I recommend using this template.
To view this demo :
.env
file at the root of the project :DATABASE_URL=file:./demo-db.sqlite?mode=memory&cache=shared
yarn && yarn prisma migrate dev
to build the databaseyarn dev
to launch the applocalhost:3000/demo
This demo is loosely based on Bulletproof React. This is simply how I prefer to organize my code but feel free to do as you please.