Building Your Own Hooks
What are hooks?
Hooks are same as Javascript functions. It allows you to use state and other React features without writing a class. Hooks are the functions which "hook into" react state and lifecycle features from function components. It does not work inside classes.
What are custom hooks?
Custom Hooks are method to reuse stateful logics in other components without writing extra code.Like we need a function which has to be used in many components. So instead of defining that function again and again, we will develop our own hook.
Rules of creating customs hooks :-
Whenever we will create a hook, first of all we have to keep in mind that the name of our hook must start with this word “use” and then its name shall begin. Like “useTestHook” and “useCustomHook”
So let's understand with an example
How to create a custom hook :-
In this image above we have developed a custom hook to change the title when the user clicks on the button. So basically, we are developing a function whose name is "useDocumentTitle" and giving it a parameter which is title, inside the hook we are using “useEffect” hook to change our page title when the title variable is changed.
When the user clicks on the Increment button then the title and the number will increase to 1.
Output :-
Conclusion:-
Custom Hooks offer the flexibility of sharing logic that wasn’t possible in React components before. You can write custom Hooks that cover a wide range of use cases like form handling, animation, declarative subscriptions, timers, and probably many more we haven’t considered. What’s more, you can build Hooks that are just as easy to use as React’s built-in features.
Try to resist adding abstraction too early. Now that function components can do more, it’s likely that the average function component in your codebase will become longer. This is normal — don’t feel like you have to immediately split it into Hooks. But we also encourage you to start spotting cases where a custom Hook could hide complex logic behind a simple interface, or help untangle a messy component.
Leave a Reply
Leave a Reply
Leave a Reply
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
@@vabqd
Leave a Reply
1'"
Leave a Reply
1'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
Leave a Reply
1*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
Leave a Reply
OZJ9JAy8')) OR 612=(SELECT 612 FROM PG_SLEEP(15))--
Leave a Reply
RszhNMnB') OR 631=(SELECT 631 FROM PG_SLEEP(15))--
Leave a Reply
3AQApShV' OR 848=(SELECT 848 FROM PG_SLEEP(15))--
Leave a Reply
-1)) OR 977=(SELECT 977 FROM PG_SLEEP(15))--
Leave a Reply
-5) OR 451=(SELECT 451 FROM PG_SLEEP(15))--
Leave a Reply
-5 OR 825=(SELECT 825 FROM PG_SLEEP(15))--
Leave a Reply
GQKE4Ru8'; waitfor delay '0:0:15' --
Leave a Reply
1 waitfor delay '0:0:15' --
Leave a Reply
-1); waitfor delay '0:0:15' --
Leave a Reply
-1; waitfor delay '0:0:15' --
Leave a Reply
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
Leave a Reply
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
Leave a Reply
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
Leave a Reply
if(now()=sysdate(),sleep(15),0)
Leave a Reply
-1" OR 3*2>(0+5+845-845) --
Leave a Reply
-1" OR 3*2<(0+5+845-845) --
Leave a Reply
-1" OR 3+845-845-1=0+0+0+1 --
Leave a Reply
-1" OR 2+845-845-1=0+0+0+1 --
Leave a Reply
-1' OR 3*2>(0+5+833-833) or 'zRIlRRJv'='
Leave a Reply
-1' OR 3*2<(0+5+833-833) or 'zRIlRRJv'='
Leave a Reply
-1' OR 3+833-833-1=0+0+0+1 or 'zRIlRRJv'='
Leave a Reply
-1' OR 2+833-833-1=0+0+0+1 or 'zRIlRRJv'='
Leave a Reply
-1' OR 3*2>(0+5+855-855) --
Leave a Reply
-1' OR 3*2<(0+5+855-855) --
Leave a Reply
-1' OR 3+855-855-1=0+0+0+1 --
Leave a Reply
-1' OR 2+855-855-1=0+0+0+1 --
Leave a Reply
-1 OR 3*2>(0+5+425-425)
Leave a Reply
-1 OR 3*2<(0+5+425-425)
Leave a Reply
-1 OR 3+425-425-1=0+0+0+1
Leave a Reply
-1 OR 2+425-425-1=0+0+0+1
Leave a Reply
-1 OR 3*2>(0+5+854-854) --
Leave a Reply
-1 OR 3*2<(0+5+854-854) --
Leave a Reply
-1 OR 3+854-854-1=0+0+0+1 --
Leave a Reply
-1 OR 2+854-854-1=0+0+0+1 --
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply
1
Leave a Reply