Giter VIP home page Giter VIP logo

namaste-react's Introduction

Namaste React

Parcel

  • It created a Dev Build
  • It created a local server
  • Automatically refreshing the page. HMR.
  • Hot Module Replacement.
  • Parcel uses a File Watching Algorithm which is written in C++.
  • Parcel gives faster builds because of caching.
  • Parcel caching is done in .parcel-cache folder.
  • Most expensive thing in web browser is to load images in to your pages.
  • Parcel does image optimization as well.
  • Parcel will bundle the files also.
  • Parcel will also compress the files of the project.
  • Consistent Hashing.
  • Code splitting.
  • Does differential bundling - support older browsers.
  • Diagnostic.
  • Error handling.
  • HTTPS.
  • Tree shaking - removes unused code.
  • Different dev and production bundles.

Tree Shaking:-

Like a tree which is having both green and brown leaves, our code also contains used and unused codes. Unused code on production should not be pushed because this will slow down the performance of the code. To avoid this, we use tree shaking technique. suppose we have two files, Math.js and index.js.

Math.js:- export const square = (a) => { return a*a; };

export const cube = (a) => { return aaa; };

index.js:- import {square} from './math';

console.log(square(3));

Here, cube function is not being used in index.js file, so we have to remove this when it goes to production. For this, in webpack.config.js file we have to use mode: 'production' under module.export and type npm run build. When the build is created, the unused code will be removed from the bundle.js file which makes the code optimized. Tree shaking will not work for commonModule.js. It will only work for ES6 static imports and exports.

Side Effects

let numbers = [1,2,3]; const addNumber = () => { number.push(num); };

this addNumber function is having a side effects because it is modifying one variable numbers which is not in its scope. The main problem of this side effect is that tree shaking can not identify which code to use or which to remove. Other example is polyfills. If you think that in your application you are not using any function which is having side effects, every function is pure function, then in package.json file, add "sideEffects": false

Tree shaking will not work with the below code: var module; if(condition) { module = require("cube"); } else { module = require("square"); }

because this code will run on the runtime and there tree shaking cannot be achieved.

/* Header Logo Nav Items Body Search Restaurant Container Img Name of Res, Star Rating, cuisines, delivery time Footer Copyright Links Address Contact */

2 type of routing in React

  • Client side routing
  • Server side routing

Redux Toolkit

  • Install Redux Toolkit and React Redux
  • Build our store
  • Connect our store to our App
  • Slice (Cart Slice)
  • Dispatch (action)
  • Read data using Selector

Types of testing (Developer)

  • Unit testing
  • Integration testing
  • End 2 End testing - e2e testing

Setting up testing in our App

  • Installed React Testing Library
  • Installed jest
  • Installed Babel dependencies
  • Configured Babel(Created babel.config.js and added some code to it)
  • npx jest --init (To configure jest)
  • install jsdom(browser-like)
  • You may have to install @babel/preset-react - to make jsx work in test cases.
  • Then you have to include @babel/preset-react inside my babel config.
  • You may have to install npm i -D @testing-library/jest-dom.

namaste-react's People

Contributors

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