REACT HOOKS
TECH47.IN & RAZORPAY
JAIKANT
KUMARAN
@JAIKANTKUMARAN
JAI@TECH47.IN
LOGISTICS
‣ Use the “General” Channel on Slack to post questions at any
point.
‣ I may ask you to refer code which is in the ‘react-hooks’ channel.
‣ We end when the talks end or by 5pm. Which ever occurs earlier.
INTRODUCTION TO HOOKS
QUESTIONS?
WHAT ARE HOOKS
Hooks lets you use state and other React features
without writing a class.
WHAT ARE HOOKS
HOOKS LET YOU WRITE STATEFUL,
FEATURE RICH FUNCTION COMPONENTS.
REACT COMPONENTS
REACT COMPONENTS
▸ CLASS COMPONENTS
▸ FUNCTION COMPONENTS
() => <div> Hi </div>
() => {
fetch('someurl');
return <div> Hi </div>;
};
Why class components - Is this good?
REACT CLASS
CLASS COMPONENT
▸ LIFE CYCLE METHODS
▸ `THIS`
▸ STATE
▸ ComponentDidMount
▸ ComponentDidUpdate
▸ComponentWillUnmount
▸…
▸ RENDER METHOD
this.state
React Classes!
this.setState(newState)
() => <div> Hi </div>
() => {
// Can do other things
return <div> Hi </div>;
};
Function Components
REACT CLASS
HOOKS
EARLIER NOW
state, setState useState
componentDidMount useEffect
componentDidUpdate useEffect
componentWillUnmount useEffect
THE SOLUTION NOW
SOME HOOKS
▸ useState
▸ useReducer
▸ useEffect
▸ useRef
▸ Custom hooks
▸useContext, useCallback, useMemo, useLayoutEffect, useImperativeHandle,
useDebugValue
WHY ARE REACT
COMPONENTS MOVING
FROM CLASSES TO HOOKS?
BETTER SOLUTION?
PROBLEMS WITH CLASSES
‣ Not possible to break the components
into smaller components as the
stateful logic is all over the
place.
‣ Classes confuse both people and machines
‣ Classes don’t minify well
‣ Make hot reloading flaky and unreliable
Hooks don’t use classes.
BETTER SOLUTION?
EXPLICIT DATA FLOW & COMPOSITION PROBLEMS WITHIN COMPONENTS
‣ Mutually related code, that changes
together gets split apart.
‣ Unrelated code ends up combined in a
single method.
Hooks lets us organise related code in a
component together. (useEffect)
BETTER SOLUTION?
EXPLICIT DATA FLOW & COMPOSITION WITHIN COMPONENTS
BETTER SOLUTION?
EXPLICIT DATA FLOW & COMPOSITION WITHIN COMPONENTS


REUSABILITY
REUSABILITY
- How do we reuse code in React?
- If components are re-usable, why do
we need hooks?
- Why sharing functions does not help?
- What was the solution earlier?
REACT.JS WORKSHOP
THANK YOU!
JAIKANT
KUMARAN
@JAIKANTKUMARAN
JAI@TECH47.IN
REACT.JS WORKSHOP
SUMMARY
‣ Hooks are javascript functions.
‣ Hooks help in code reusability.
‣ Hooks help split a component into
smaller functions based on whats
related.
‣ Hooks are easy to share amongst
components or with community.
REACT.JS WORKSHOP
NEXT STEPS
▸ Read about hooks at https://reactjs.org/docs/hooks-
intro.html
▸ Start using hooks in your projects.
REACT.JS WORKSHOP
Lets continue the conversation on the
Slack Channel!
Next Meetup - March 23rd

React.js hooks feb 23rd meetup