DEV Community

Cover image for REACT -> HOOKS!
BigBitDev
BigBitDev

Posted on

REACT -> HOOKS!

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:

  1. They can only be called within a component
  2. 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>
  );
}

Enter fullscreen mode Exit fullscreen mode

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)

Collapse
bulmaroarellano profile image
bulmaroarellano •

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.

Collapse
bigbitdev profile image
BigBitDev Author •

Heyy thx for share it! try harder Pal! 😁