Skip to content
Myr

shallow.ts

This file

Path

src/react/shallow.ts

12 lines · 354 bytes · TypeScript

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than f85898f point at it.

chore(eslint.config.mjs): update 'eslint-plugin-react-hooks', 'eslint-plugin-react-compiler' config (#3043)Wonsuk Choibefore adoptionf85898f

lines 1–12why, one step back
1import React from 'react'
2import { shallow } from '../vanilla/shallow.ts'34export function useShallow<S, U>(selector: (state: S) => U): (state: S) => U {5 const prev = React.useRef<U>(undefined)6 return (state) => {7 const next = selector(state)8 return shallow(prev.current, next)9 ? (prev.current as U)10 : (prev.current = next)11 }12}