You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+94-1Lines changed: 94 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -157,7 +157,16 @@ Below is a list of ReactJS interview questions and answers.
157
157
|149|[What are the different ways to write mapDispatchToProps?](#what-are-the-different-ways-to-write-mapDispatchToProps)|
158
158
|150|[What is the use of the ownprops arg in mapStateToProps and mapDispatchToProps?](#what-is-the-use-of-the-ownprops-arg-in-mapstatetoprops-and-mapdispatchtoprops)|
159
159
|151|[How to structure redux top level directories?](#how-to-structure-redux-top-level-directories)|
160
-
160
+
|152|[What is redux saga?](#what-is-redux-saga?)|
161
+
|153|[What is the mental model of redux saga?](#what-is-the-mental-model-of-redux-saga)|
162
+
|154|[What are the differences between call and put in redux-saga](#what-are-the-differences-between-call-and-put-in-redux-saga)|
163
+
|155|[What is Redux thunk?](#what-is-redux-thunk)|
164
+
|156|[What are the differences between redux-saga and redux thunk](#what-are-the-differences-between-redux-saga-and-redux-thunk)|
165
+
|157|[What is React Dev Tools?](#what-is-react-dev-tools)|
166
+
|158|[Why React tab is not showing up for dev tools?](#why-react-tab-is-not-showing-up-for-dev-tools)|
167
+
|159|[What is Redux DevTools?](#what-is-redux-devtools)|
168
+
|160|[What are the features of Redux DevTools?](#what-are-the-features-of-redux-devtools)|
169
+
|161|[How to focus an input element on page load?](#how-to-focus-an-input-element-on-page-load)|
161
170
162
171
### What is ReactJS?
163
172
@@ -1558,6 +1567,10 @@ Redux follows three fundamental principles
1558
1567
1559
1568
### What are Redux selectors?Why use them?
1560
1569
Selectors are functions that take Redux state as an argument and return some data to pass to the component.
1570
+
For example, to get user details from the state,
1571
+
```
1572
+
const getUserData = state => state.user.data;
1573
+
```
1561
1574
1562
1575
### What is reselect?How it works?
1563
1576
Reselect is a selector library(for Redux) which uses memoization concept. It was originally written to compute derived data from redux-like applications state, but it cann't be tied to any architecture or library.
@@ -2355,3 +2368,83 @@ Most of the applications has several top-level directories as below
2355
2368
5.**Store** Used for store initialization
2356
2369
This structure works well for small and mid-level size apps.
2357
2370
2371
+
### What is redux-saga?
2372
+
redux-saga is a library that aims to make side effects(i.e. asynchronous things like data fetching and impure things like accessing the browser cache) in React/Redux applications easier and better.
2373
+
It is available in NPM as
2374
+
```
2375
+
npm install --save redux-saga
2376
+
```
2377
+
### What is the mental model of redux-saga?
2378
+
The mental model is that a saga is like a separate thread in your application that's solely responsible for side effects. redux-saga is a redux middleware, which means this thread can be started, paused and cancelled from the main application with normal redux actions, it has access to the full redux application state and it can dispatch redux actions as well.
2379
+
### What are the differences between call and put in redux-saga?
2380
+
Both **call** and **put** are effects creators functions. call function is used to create effect description, which instructs middleware to call the promise. put function creates effect, in which instructs middleware to dispatch an action to the store.
2381
+
Let's take example of how these effects work for fetching particular user data
2382
+
```
2383
+
function* fetchUserSaga(action) {
2384
+
// `call` function accepts rest arguments, which will be passed to `api.fetchUser` function.
2385
+
// Instructing middleware to call promise, it resolved value will be assigned to `userData` variable
// Instructing middleware to dispatch corresponding action.
2388
+
yield put({
2389
+
type: 'FETCH_USER_SUCCESS',
2390
+
userData
2391
+
});
2392
+
}
2393
+
```
2394
+
### What is Redux thunk?
2395
+
Redux Thunk middleware allows you to write action creators that return a function instead of an action. The thunk can be used to delay the dispatch of an action, or to dispatch only if a certain condition is met. The inner function receives the store methods dispatch and getState() as parameters.
2396
+
### What are the differences between redux-saga and redux-thunk?
2397
+
Both Redux Thunk and Redux Saga take care of dealing with side effects. In most of the scenarios, Thunk allows Promises" to deal with them, whereas Saga uses Generators. Thunk is simple to use and Promises are familiar to many developers, Saga/Generators are more powerful but you will need to learn them. But both the two middleware can coexists, so you can start with Thunks and introduce Sagas when/if you need them.
2398
+
### What is React Dev Tools?
2399
+
React Developer Tools makes you inspect the React component hierarchy, including component props and state. It exists both as a browser extension (for Chrome and Firefox), and as a standalone app (works with other environments including Safari, IE, and React Native).
2400
+
The official extensions available for different browsers or environments.
2401
+
1.**Chrome extension**
2402
+
2.**Firefox extension**
2403
+
3.**Standalone app (Safari, React Native, etc)**
2404
+
After installation the quick navigation icon would appear as below,
2405
+

2406
+
and creates React new tab as below,
2407
+

2408
+
### Why React tab is not showing up for dev tools?
2409
+
When the page loads, the devtools sets a global named __REACT_DEVTOOLS_GLOBAL_HOOK__, then React communicates with that hook during initialization. If the website is not using React or if React fails to communicate with DevTools then it won't show up the tab.
2410
+
### What is Redux DevTools?
2411
+
Redux DevTools is a live-editing time travel environment for redux with hot reloading, action replay, and customizable UI. If you don’t want to bother with installing Redux DevTools and integrating it into your project, consider using Redux DevTools Extension for Chrome and Firefox.
2412
+
### What are the features of Redux DevTools?
2413
+
Below are the major features of redux devTools
2414
+
1. Lets you inspect every state and action payload
2415
+
2. Lets you go back in time by “cancelling” actions
2416
+
3. If you change the reducer code, each “staged” action will be re-evaluated
2417
+
4. If the reducers throw, you will see during which action this happened, and what the error was
2418
+
5. With persistState() store enhancer, you can persist debug sessions across page reloads
0 commit comments