Interview Questions & Answers

react-js

Flux

  • Store contains state and change logic
  • Multiple stores
  • Flat disconnected stores
  • Singleton dispatcher
  • React components subscribe to the store
  • State is mutable

Redux

  • Store and change logic are separate
  • Single Store
  • Single store with hierarchical reducers
  • No dispatcher
  • Container components utilize connect
  • State is immutable

  • A store is a JavaScript object which can hold the application’s state.
  • And it provides a few helper methods to access the state, dispatch actions and register listeners.
  • With Store the data state can be synchronized from the server level to the client layer without much hassle.
  • This makes the development of large applications easier and faster.
import { createStore } from ‘redux’
import todoApp from ‘./reducers’
let store = createStore(reducer);

  • Reducers are pure functions which specify how the applications state changes in response to an ACTION.
  • Takes in the previous state and an action and returns the new state type of the action, and returns new values.
  • Determines what sort of update needs to be done based on the type of the action, and returns new values.
  • It returns the previous state if no work needs to be done.

  • Must have type property that indicates the type of ACTION Being performed.
  • They must be defined as String constant.
  • You can add more properties to it.
  • Actions are created using functions called Action Creators.
function addTodo(text)
{
  return
  {
    type: ADD_TODO,
    text
  }
}

  1. Action – It’s an object that describes what happened.
  2. Reducer – It is a place to determine how the state will change.
  3. Store – State/Object tree of the entire application is saved in the store.
  4. View – Simply displays the data provided by the Store.

  • Redux uses Store for storing all the application state at one place.
  • Components state is stored in the Store and they receive updates from the store itself.
  • The single state tree makes it easier to keep track of changes over time and debug or inspect the application.

  1. Single source of truth.
  2. State is read-only
  3. Changes are made with pure functions.

  • Redux one of the hottest libraries for front end development.
  • Redux is a predictable state container for JavaScript apps.
  • Mostly used for applications state Management.
  • Applications developed with Redux are easy to test.
  • Helps to write applications that behave consistently and can run in different environments.