Skip to content

Instantly share code, notes, and snippets.

View aungthuoo's full-sized avatar
💭
I am looking for a job.

Aung Thu Oo @ Andrew Maung aungthuoo

💭
I am looking for a job.
View GitHub Profile
@aungthuoo
aungthuoo / throttling-and-debouncing.md
Created February 16, 2024 09:33
Today I learned about the throttling effect from the internet and I got confused as it seem similar to debouncing by definition.

Throttling and Debouncing - Explained

Hello readers! Today I learned about the throttling effect from the internet and I got confused as it seem similar to debouncing by definition. But after further reading and research, I understood the difference between throttling and debouncing.

Here in this article, I want to share this knowledge with you all.

Introduction

Throttling and debouncing are techniques used to control the rate at which a function is invoked, particularly in scenarios where frequent events (like user interactions) can lead to excessive calls and potentially impact performance.

@aungthuoo
aungthuoo / reactjs-interview-questions.md
Created February 16, 2024 13:17
ReactJs Interview Question 2024 [50+ Questions]
title description githubPath
ReactJs Interview Question 2024 [50+ Questions]
Find the top React job 50+ Questions interview questions for 2024 for beginners, frontend developers, junior developers as well as for experienced developers which might help you cracking your next interview.

Updated Jan 07, 2024

Here you'll find the top 50+ React job interview questions for 2024 for beginners, frontend developers, junior developers as well as for experienced developers which might help you cracking your next interview.

What is a React component?

A React component represents a modular, reusable piece of the user interface. It can encapsulate both visual elements (rendered in the Virtual DOM) and application logic. React components come in two primary forms: function components and class components.

Function vs. Class Components

  • Function Components: These are stateless, simpler to read, and ideally used for small, specialized UI elements known as 'dumb' components. They are pure functions, perceptually faster because of fewer checks.

  • Class Components: These can maintain state and expose more advanced features like lifecycle methods. However, the introduction of hooks to function components in React 16.8 technically made state management possible without classes.

How do you create a component in React?

Creating a React component involves defining its structure, behavior, and sometimes lifecycle methods for dynamic updates. Components can be functional or class-based.

Code Example

Here's a Class-based component:

import React, { Component } from 'react';

What is JSX and why do we use it in React?

JSX is a powerful JavaScript Extension that enables the seamless integration of HTML-like structures within React. Notably, it allows for a more intuitive component declaration and enhanced developer productivity.

Key Features

  • Readable Syntax: Familiar HTML tags make parsing code and debugging simpler.

  • Component Embedding: JSX supports direct embedding of components, which enhances modularity.

Can you explain the virtual DOM in React?

The Virtual DOM is a key concept in React, responsible for its high performance. It efficiently manages the DOM setup, minimizes updates, and then syncs them to the actual DOM tree.

How the Virtual DOM Works

  1. Initial Rendering: When the application starts, React creates a simplified in-memory representation of the DOM, called the Virtual DOM.

  2. Tree Comparison: During each state change, React builds a new Virtual DOM representation. It then compares this updated representation against the previous one to identify what has changed. This process is often called "reconciliation".

What are the differences between a class component and a functional component?

Let's look at the various aspects and differences between Class Components and Functional Components.

Core Distinctions

Class Components:

  • Utilize the class keyword for component definition.
  • Can have state management.

How do you handle events in React?

React simplifies the process of managing and handling events through its use of synthetic events.

Handling Events in React

Synthetic Events

React abstracts browser events into what are known as synthetic events. This ensures a consistent interface across different browsers.

What are state and props in React?

In React, props and state are both used to propagate and manage data. However, they have different roles and management patterns.

Role & Life Cycle

  • Props (short for "properties") are used to pass data from a parent component to a child one. Once passed, props in the child component are read-only and can't be directly modified by the child.

  • State is used to manage data within a component, and is mutable. Any changes to state values trigger a component re-render.

How do you pass data between components in React?

Data propagation in React components primarily relies on two mechanisms:

  • Props: For unidirectional data flow, parent components pass data to their children via props.

  • Callback Functions: Data moves up the tree when children invoke specific functions passed down from their parents.

Let's have a look at the best-practices for these two mechanisms.