Hello react community! Today I'm here to share some of my knowledge about REACT! As I said in the title, today I will talk about hooks! but don't be afraid that the only thing they hook is data, not people! 🤣
Hook Hook Hurray!
As everything in life hooks despite being a powerful tool have their rules:
- They can only be called within a component
- They cannot be conditional
There are several types of hooks:
- useState
- useMemo
- useEffect
- useCallback
- useContext
I would lack characters to explain the possibilities we would do with them so I'll give you an example to get you "hooked" do you get it?
The classic click counter:
import React, { useState } from 'react';
function Example() {
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}
Extra NOTES:
- Hooks were added to React in version 16.8
- Generally replace class components and Hooks will not work on it!
- Hooks have to be embedded in the react import so that you can use them! import React, {Hook} from 'react';
Well good people of the internet I believe that hooks are a powerful tool that will allow us to improve our code! I want to know your opinion! See you in the next post ! BYE BYE! 🥰😍😍
Discussion (2)
Hey!!
Thank you very much for sharing this introduction to the topic. I hardly know React and with this I finish my day, tomorrow to study the subject of hooks in depth.
Heyy thx for share it! try harder Pal! 😁