Skip to content

Instantly share code, notes, and snippets.

View elyor-sh's full-sized avatar
🎯
Focusing

Elyor Shodiyorov elyor-sh

🎯
Focusing
View GitHub Profile
@elyor-sh
elyor-sh / createContexts.ts
Last active October 23, 2025 13:11
createContexts: Creates multiple React contexts
import {makeAutoObservable} from "mobx";
import React, {type Context, createContext, type FC, type PropsWithChildren, useRef} from "react";
export function createContexts<T extends Record<string, () => any>>(factories: T) {
type Keys = keyof T & string;
type Instances = { [K in Keys]: ReturnType<T[K]> };
const out = {} as {
[K in Keys as `${K}Provider`]: FC<PropsWithChildren<{}>>
@elyor-sh
elyor-sh / useLocalState.tsx
Last active October 23, 2025 11:17
How to get rid of the hooks in React? Example for local state
import {makeAutoObservable} from "mobx";
import {observer} from "mobx-react-lite";
class CounterState {
count = 0
constructor() {
makeAutoObservable(this, {}, {autoBind: true})
}
@elyor-sh
elyor-sh / Counter.tsx
Last active October 22, 2025 06:33
useAutoEffect example - Intercept dependencies automatically
import {useTrackedState, useAutoEffect} from './useAutoEffect.ts'
// example
const Counter = () => {
const [count, setCount] = useTrackedState(0);
useAutoEffect(() => {
console.log("Called one time")
})