Git Product home page Git Product logo

react-snippets-simplified's Introduction

React-snippets: simplified

A collection of snippets without the redux/native bloat.

Made for daily use when developing react-applications.

Snippets

Snippet
useEffect useEffect
useLayoutEffect useLayoutEffect
useState useState
useCallback useCallback
useContext useContext
useMemo useMemo
useRef useRef
useTransition useTransition
useEvent custom event hook
cla className
cl console.log

Description

useEffect

useEffect(() => {

  return () =>
}, [])

useLayoutEffect

useLayoutEffect(() => {

  return () =>
}, [])

useState

// JS
const [state, setState] = useState();

// TS
const [state, setState] = useState<type>();

useCallback

const callback = useCallback(() => {
  func(a);
}, [a]);

useContext

// JS
const context = useContext(ctx);

// TS
const context = useContext<type>(ctx);

useMemo

// JS
const value = useMemo(() => calc(a), [a]);

// TS
const value: type = useMemo(() => calc(a), [a]);

useRef

// JS
const ref = useRef(null);

// TS
const ref = useRef<type>(null);

useTransition

const [isPending, startTransition] = useTransition();

useEvent

Not used often, but when needed its a pain to boilerplate.

const callback = useCallback(() => {
  calc(a);
}, [a]);

useEffect(() => {
  window.addEventListener(event, callback);

  return () => {
    window.removeEventListener(event, callback);
  };
}, [callback]);

cla

For the extra lazy (like me)

className = ""

cl

Logs output in object format

console.log({ value });

react-snippets-simplified's People

Contributors

kenajoh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.