Skip to content

Instantly share code, notes, and snippets.

@kentcdodds
kentcdodds / create-simple-context.tsx
Last active September 24, 2021 08:42
A simple context creator that doesn't allow any logic. It's 100% just to make it easy to pass a value from a parent to all children, specifically useful for remix where you just want a loader's data to be accessible anywhere else in your tree.
function createSimpleContext<ContextType>(name: string) {
const defaultValue = Symbol(`Default ${name} context value`)
const Context =
React.createContext<ContextType | null | typeof defaultValue>(defaultValue)
Context.displayName = name
function useValue() {
const user = React.useContext(Context)
if (user === defaultValue) {
throw new Error(`use${name} must be used within ${name}Provider`)
@swalkinshaw
swalkinshaw / tutorial.md
Last active November 13, 2023 08:40
Designing a GraphQL API
@manigandham
manigandham / rich-text-html-editors.md
Last active May 3, 2024 19:37
Rich text / HTML editors and frameworks

Strictly Frameworks

Abstracted Editors

These use separate document structures instead of HTML, some are more modular libraries than full editors

@idosela
idosela / http-response-interceptor.js
Last active February 25, 2024 12:51
Sample code for ng-conf 2014
angular.module('myMdl', []).config(['$httpProvider', function($httpProvider) {
$httpProvider.responseInterceptors.push([
'$q', '$templateCache', 'activeProfile',
function($q, $templateCache, activeProfile) {
// Keep track which HTML templates have already been modified.
var modifiedTemplates = {};
// Tests if there are any keep/omit attributes.
var HAS_FLAGS_EXP = /data-(keep|omit)/;
@jelbourn
jelbourn / api-provider.js
Last active February 25, 2024 12:51
Example of using an angular provider to build an api service. Subject of August 20th 2013 talk at the NYC AngularJS Meetup. http://www.meetup.com/AngularJS-NYC/events/134578452/See in jsbin: http://jsbin.com/iWUlANe/5/editSlides: https://docs.google.com/presentation/d/1RMbddKB7warqbPOlluC7kP0y16kbWqGzcAAP6TYchdw
/**
* Example of using an angular provider to build an api service.
* @author Jeremy Elbourn (@jelbourn)
*/
/** Namespace for the application. */
var app = {};
/******************************************************************************/