Skip to content

Instantly share code, notes, and snippets.

@leomiranda
leomiranda / remix.ts
Last active March 22, 2024 15:43
Remix
// Helper: check data and throw error (loader and action)
/**
* Provide a condition and if that condition is falsey, this throws a 400
* Response with the given message.
*
* inspired by invariant from 'tiny-invariant'
*
* @example
import { ActionArgs, json } from '@remix-run/node';
import { useActionData, useSubmit } from '@remix-run/react';
import { useState } from 'react';
export async function action({ request }: ActionArgs) {
const body = await request.formData();
const data = JSON.parse(body.get('data') as string);
const firstName = data?.user?.first_name;
return json({ message: `Hello, ${firstName}` });
@leomiranda
leomiranda / list.vue
Created March 20, 2019 17:58
list.vue
<template>
<div class="q-mt-lg">
<q-card v-for="expense in expenses" :key="expense.date" class="q-mb-md cc-card" @click="ccToggle(expense)">
<q-card-title>
R$ {{ expense.amount }}
<span :class="{ done: expense.done }" slot="subtitle" v-html="dateFormat(expense.date)"></span>
</q-card-title>
<q-card-separator />
<q-card-main :class="{ done: expense.done }">
{{ expense.description }}