What is HR Automation?
It is a feature introduced to play with states in functional components as previously it was just being used with class components only. Hooks are the functions which “hook into” React state and life cycle features from function components. RULES FOR USING HOOKS: (1)- Only call hooks at top level (2)- Only call hooks from react function SYNTAX INVOLVED WITH USING STATE IN HOOKS:
import React, {useState} from ‘React;
- importReact, { useState } from ‘react’;
- function CountApp() {
- // Declare a new state variable, which we’ll call “count”
- const [count, setCount] = useState(0);
- return (
- <div>
- <p>You clicked {count} times</p>
- <button onClick={() => setCount(count + 1)}>
- Click me
- </button>
- </div>
- );
- }
- export defaultCountApp;
BASIC HOOKS:
(1)- useState()
(2)- useEffect()
(3)- useContext()
Sana Eram
Data Scientist Intern