state-management

typescript
export interface QueryCodec<T> {
  parse: (raw: string | null) => T;
  serialize: (value: T) => string | null;
}

export function stringParam(fallback = ""): QueryCodec<string> {

Sync Typed Form State to the URL Query String with a useQueryState Hook

react hooks url-state
by codesnips 3 tabs
typescript
import { Injectable } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

@Injectable()
export class SignupFormService {
  readonly form: FormGroup;

Multi-Step Signup Wizard in Angular with a Shared FormGroup and Stepper Service

angular reactive-forms wizard
by codesnips 4 tabs
typescript
import { createContext } from 'react';

export type ToastVariant = 'success' | 'error' | 'info';

export interface Toast {
  id: number;

Imperative Toast Notification System with React Context and Auto-Dismiss

react toast context
by codesnips 4 tabs
javascript
import React, { createContext, useContext, useReducer, useState } from 'react';

// 1. Basic Context
const UserContext = createContext(null);

function UserProvider({ children }) {

State management with Context API and Redux patterns

react redux state-management
by Alex Chang 2 tabs
javascript
import { useState, useEffect, useCallback } from 'react';

export function useLocalStorage(key, initialValue) {
  const readValue = useCallback(() => {
    if (typeof window === 'undefined') return initialValue;
    try {

Persist a React Shopping Cart to localStorage with a Context Provider

javascript react context
by codesnips 3 tabs
ruby
require 'sinatra/base'
require_relative 'cart'
require_relative 'cart_helpers'

class StoreApp < Sinatra::Base
  enable :sessions

Session-Backed Shopping Cart with Sinatra Helpers and a Cart Value Object

sinatra sessions shopping-cart
by codesnips 3 tabs
typescript
export interface CartItem {
  id: string;
  name: string;
  price: number;
  quantity: number;
}

Type-Safe Shopping Cart with useReducer, Context, and a useCart Hook

react context usereducer
by codesnips 4 tabs