Shoes

Jhankhar Mahbub

Mar 20

5 min read

What is the demand for web development?

#beginners #programming


Shoes

Anisul Islam

Mar 25

7 min read

How much Git and Github you should learn?

#beginners #programming


Shoes

Sumit Saha

Mar 3

10 min read

Everything you need to know about pipe and compose functions in JavaScript

#beginners #programming


Shoes

Nayem Hasan

Mar 10

9 min read

The Power of Asynchronous Programming in JavaScript

#beginners #programming


Spent time on read: 0

Bookmarked Blogs:


Question and Answer Section

1. What is the difference between Props and State?

PROPS
1. Props like a argument that we pass a function.
2. Props are use to pass data Parent Component to Child Component.
3. Props are immutable.
4. Props are read-only.
State
1. State like a component memory.
2. The state is a local storage that is local to component only and cannot be passed to other components.
3. State is mutable.
4. State changes can be asynchronous (read and write).
5. State allow to any component to keep track for some information and change interactions response.

2. How does useState works?

useState is React Hookthat lets you add a state variable to your component.
Syntax:
const [state, setState] = useState(initialValue);
Case-1: Behind the useState() hook
useState is a function that accepts the initial state as an argument and returns a state value and a function to update this value. This ensures that the React preserves the state between re-renders. The useState hook can be used to keep track of strings, numbers, booleans, arrays, objects, and any combination of these.
Case-2: useState() is asynchronous
useState() work asynchronous way. React is not updating the state value immediately after the function call. It enqueues this operation and after the component gets re-rendering the state value is updated with the most recent state value. Thus if we try to use the state value to store to Database or pass to some other function before component re-render then we will end up with the previous value. This explains the asynchronous behavior of useState even though it doesn't return a Promise.

3. What does useEffect do except data loading?

The useEffectin react js allows you to perform side effects in your components. The react useEffect examples of side effects include retrieving data, direct DOM updates, and timers. The second argument is optional.
useEffect use cases
1. Running once on mount: fetch API data
2. Running on state change: validating input field
3. Running on state change: live filtering
4. Running on state change: trigger animation on new array value
5. Running on props change: update paragraph list on fetched API data update
6. Running on props change: updating fetched API data to get BTC updated price

4. How does React work?

Reacton its own it just a library that allows us to define components, elements and so on + it does the diffing part. Most of the actual implementation lives in the renders. They begin the reconciliation process. They generate the tree of elements and insert it wherever it has to be inserted. You can create your own renderer using the react-test-renderer package.
In terms of web development, we usually only import React DOM once and call its render() method. How can most of the implementation live in the render package? The key to understanding this is to know that React communicates with the rendered. There are many ways of React doing that, but let's explore one of them, the setState function.
How exactly does setState() work?
set State is part of class components and the answer is that every renderer sets a special field on the created class. This field is called updater. When we use React on the web, it is React DOM that sets this field right after creating an instance of the class.
What about React Hooks?
React hooks basically do the same thing, however, instead of an updater field, they use a dispatcher object. Internally, it looks similarly to this.