Skip to content

Instantly share code, notes, and snippets.

On reusable components API design

Let’s compare the different ways Space Kit’s is implemented vs Chakra’s .

Starting with the base case:

@cheapsteak
cheapsteak / usePromptState.ts
Created December 30, 2020 21:13
helper for creating prompts that can be awaited on
import { useCallback, useRef, useState } from "react";
export const cancelledSymbol = Symbol("Cancelled");
export function usePromptState<
PromptResults,
PromptFunction extends Function = () => void
>({ stableOnPrompt }: { stableOnPrompt?: PromptFunction } = {}) {
const [isOpen, setIsOpen] = useState<boolean>(false);
const _ = require("lodash");
const got = require("got");
const getHourlyForecast = async () => {
const { body } = await got("https://api.climacell.co/v3/weather/forecast/hourly", {
method: "GET",
searchParams: {
lat: process.env.LAT,
lon: process.env.LON,
unit_system: "si",
const netlifyHost = 'my-app.netlify.app';
const shouldAllowCORS = (origin) => {
if (/http\:\/\/localhost:/.test(origin)) {
return true;
}
if (origin === (`https://${netlifyHost}`) || (new RegExp(`--${netlifyHost.replace(/\./g, '\.')}`)).test(origin)) {
return true;
}
return false;
import React from 'react';
// Create the hook that contains state as you normally would, don't worry about context
// Note that this is _not_ exported
const useSomeState = () => {
const [someState, setSomeState] = React.useState();
return {
someState,
setSomeState,
};
  • Precedence doesn't work as you'd expect (twin.macro and twind solve this)
 const SomeComponent = ({ className }) =>
   <div className={classnames('bg-red', className)} />

 <SomeComponent className="bg-blue"/>

What background color will the component have? The div will end up with class="bg-red bg-blue", so precedence depends on whether the specifiers for .bg-red was generated before or after specifiers for .bg-blue in the css file

  • variants conflicting because you have to specify their order globally in the config, not case-by-case - @JonasKuske (twin.macro and twind solve this)

AWS

Strengths

  • Most popular / "Safest" option
  • 1 year free trial
  • Elastic Beanstalk auto scaling
  • Good platform to learn / have on resume

Weaknesses

  • Time cost from initial configs (including Elastic Beanstalk scaling options, CloudWatch billing alerts)
(function(module) {
try {
module = angular.module('templates');
} catch (e) {
module = angular.module('templates', []);
}
module.run(['$templateCache', function($templateCache) {
$templateCache.put('404/templates/404.html',
'<div class="container-fluid text-center not-found"><h1 data-translate="">Page Not Found</h1><p data-translate="">You have searched for something that doesn\'t exist!</p><a href="/">Go back to the home page.</a></div>');
}]);