REACT HOOKS: USESTATE (01)

REACT HOOKS:

Hi, Welcome to most simplified article on react hooks, if you’re interested in react, don’t skip!
React hooks are basically built-in functions that performance specific tasks, react have about 10(or more) hooks. Each having a specific way…


This content originally appeared on DEV Community and was authored by Stanley Enumah

REACT HOOKS:

Hi, Welcome to most simplified article on react hooks, if you’re interested in react, don’t skip!
React hooks are basically built-in functions that performance specific tasks, react have about 10(or more) hooks. Each having a specific way of declaration and usage. React hooks all have “use” prefix, example useState, useEffect.
Let’s dive in!
React hook rules;

  1. The most important, only call hooks at the top level of the function component
  2. Don’t declare hooks conditionally Basic React Hooks;
  3. useState
  4. useEffect
  5. useRef Other React Hooks;
  6. useReducer
  7. useMemo
  8. useContext
  9. useDebugValue These are not the only hooks, at a beginner/intermediate level, the basic ones are mostly used. Let’s discuss the most used react hook, useState This is as the name is, it’s used to stored and mutable the state of a react component, it can do things like controlling when to show a p tag, controlling input fields, changing an array. Infact, anything that is to change in the UI is mostly controlled using useState. useState can take in string, number boolean, array and a call back function, leaving the initial state empty will result to undefined An example; In this example we want to display the message “Good afternoon” when we click the button “greet”, here’s the syntax;

` function App() {
/declaring the state/
const [show, setShow] = useState(false);

/function to change the state/
function handleShow() {
setShow(true);
}
return (


{show ?

Good afternoon

: ""}
greet

);
}`

Explanation: on clicking the greet button, the show state changes from false to true and the p tag shows if not it won’t this is because its handled by the show state.

In the next article, we will consider more examples of the use of useState, salam guys!
Don’t forget to drop a comment.


This content originally appeared on DEV Community and was authored by Stanley Enumah


Print Share Comment Cite Upload Translate Updates
APA

Stanley Enumah | Sciencx (2025-01-28T20:35:40+00:00) REACT HOOKS: USESTATE (01). Retrieved from https://www.scien.cx/2025/01/28/react-hooks-usestate-01/

MLA
" » REACT HOOKS: USESTATE (01)." Stanley Enumah | Sciencx - Tuesday January 28, 2025, https://www.scien.cx/2025/01/28/react-hooks-usestate-01/
HARVARD
Stanley Enumah | Sciencx Tuesday January 28, 2025 » REACT HOOKS: USESTATE (01)., viewed ,<https://www.scien.cx/2025/01/28/react-hooks-usestate-01/>
VANCOUVER
Stanley Enumah | Sciencx - » REACT HOOKS: USESTATE (01). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/01/28/react-hooks-usestate-01/
CHICAGO
" » REACT HOOKS: USESTATE (01)." Stanley Enumah | Sciencx - Accessed . https://www.scien.cx/2025/01/28/react-hooks-usestate-01/
IEEE
" » REACT HOOKS: USESTATE (01)." Stanley Enumah | Sciencx [Online]. Available: https://www.scien.cx/2025/01/28/react-hooks-usestate-01/. [Accessed: ]
rf:citation
» REACT HOOKS: USESTATE (01) | Stanley Enumah | Sciencx | https://www.scien.cx/2025/01/28/react-hooks-usestate-01/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.