Ip QB (Unit 4)
Ip QB (Unit 4)
Ip QB (Unit 4)
UNIT 4
In Flux application, data flows in a single direction(unidirectional). This data flow is central to the flux pattern.
The dispatcher, stores, and views are independent nodes with inputs and outputs. The actions are simple
objects that contain new data and type property. Now, let us look at the various components of flux
architecture one by one.
Dispatcher
It is a central hub for the React Flux application and manages all data flow of your Flux application. It is a
registry of callbacks into the stores. It has no real intelligence of its own, and simply acts as a mechanism for
distributing the actions to the stores. All stores register itself and provide a callback. It is a place which
handled all events that modify the store. When an action creator provides a new action to the dispatcher, all
stores receive that action via the callbacks in the registry.
The dispatcher's API has five methods. These are:
Stores
It primarily contains the application state and logic. It is similar to the model in a traditional MVC. It is used for
maintaining a particular state within the application, updates themselves in response to an action, and emit
the change event to alert the controller view.
Views
It is also called as controller-views. It is located at the top of the chain to store the logic to generate actions
and receive new data from the store. It is a React component listen to change events and receives the data
from the stores and re-render the application.
Actions
The dispatcher method allows us to trigger a dispatch to the store and include a payload of data, which we
call an action. It is an action creator or helper methods that pass the data to the dispatcher.
Advantage of Flux
• It is open source and more of a design pattern than a formal framework like MVC architecture.
Types of Hooks
There are several types of Hooks in React, including:
1) State Hooks
• State Hooks allow you to add state to functional components. The most common State Hook
is useState.
• useState
• useState is a Hook that allows you to add state to functional components. It takes an initial value as an
argument and returns an array with the current state value and a function to update it.
2) Effect Hooks
• Effect Hooks allow you to run side effects in functional components. The most common Effect Hook
is useEffect.
• useEffect
• useEffect is a Hook that allows you to run side effects in functional components. It takes a function as
an argument, which is executed after the component has rendered or updated.
3) Context Hooks
• Context Hooks allow you to subscribe to context changes in functional components. The most
common Context Hook is useContext.
• useContext
• useContext is a Hook that allows you to subscribe to context changes in functional components. It
takes a context object as an argument and returns the current value of the context.
4) Ref Hooks
• Ref Hooks allow you to create refs in functional components. The most common Ref Hook is useRef.
• useRef
• useRef is a Hook that allows you to create refs in functional components. It takes an initial value as an
argument and returns a ref object.
5) Callback Hooks
• Callback Hooks allow you to memoize functions in functional components. The most common Callback
Hook is useCallback.
• useCallback
• useCallback is a Hook that allows you to memoize functions in functional components. It takes a
function as an argument and returns a memoized version of the function.
6) Memo Hooks
• Memo Hooks allow you to memoize values in functional components. The most common Memo Hook
is useMemo.
• useMemo
• useMemo is a Hook that allows you to memoize values in functional components. It takes a function
as an argument and returns a memoized value.