useToggle Custom hook

Dogendar 🐶 is very fond of writing custom hooks and today he wants to write a custom hook called useToggle. The hook is supposed to return a boolean value along with a toggler function that toggles the value on invocation. Toggle means if the value is true, then it will be changed to false and vice-versa.

It can be used like

const { value, toggleValue } = useToggle(true) // toggleValue() will toggle the value and rerender parent component

Help Dogendar write the custom hook given below and fulfil these requirements:

  • return value and toggleValue function from the hook
  • initially, the hook should return the given initial value in parameters
  • when toggleValue is called, the returned value should be toggled



Solve the practice problems to earn    DevCoin image 
Coding Area

Copyright © 2022 opendevs

Learn ● Develop ● Ace
All illustrations by Storyset