GithubHelp home page GithubHelp logo

custom-hooks's Introduction

Custom Hooks

This repo aims to dive deep into the applications of custom hooks and how they make the code clean and more readable.

Make sure that the backend(used in the auto refresh hook) is active at : https://dummy-server-for-react-js-lazy-loading.onrender.com

1. useAutoRefresh hook :

This hook demonstrates the concept of polling(by using useEffect, useState, setInterval and axios internally) to get dynamic data and separation of concerns by creating a hook and importing it into the main file which gives loading, error, data so that it could be used in suitable cases for UI rendering and ultimately making the code more readable and clean.

2. useInterval hook :

This hook takes a function and a number as inputs and executes the said function at the given intervals.

3. useIsOnline hook :

Using the window.navigator.onLine functionality, we check if the user is connected to Internet or not, and display the current status.

4. useMousePosition hook :

This hook uses the mousemove event and attaches it to the window object and then we use the event.clientX and event.clientY properties given by the event object to get the position of the mouse on the screen and display it on the screen.

5. useDebounce hook :

This hook is used to basically reduce the number of API calls or reduce the number of operations which include the server by updating the inputs after the user stops typing or stops giving an input and then registering it and acting on it rather acting on the input whenever it changes as that could lead to un-necessary API calls or expensive computation on the server.

custom-hooks's People

Contributors

rajneesh069 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.