Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/pages/useToggle.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ isMultilingual: true
---

Basically, what this hook does is that, it takes a parameter with value true or false and toggles that value to opposite.
It's useful when we want to take some action into it's opposite action, for example: show and hide modal, show more/show less text, open/close side menu.
It's useful when we want to take some action into its opposite action, for example: show and hide modal, show more/show less text, open/close side menu.


```jsx
Expand All @@ -31,8 +31,8 @@ const useToggle = (initialState = false) => {
// Initialize the state
const [state, setState] = useState(initialState);

// Define and memorize toggler function in case we pass down the comopnent,
// This function change the boolean value to it's opposite value
// Define and memoize the toggler function in case we pass down the component,
// This function change the boolean value to its opposite value
const toggle = useCallback(() => setState(state => !state), []);

return [state, toggle]
Expand All @@ -45,7 +45,7 @@ import { useCallback, useState } from 'react';

// Usage
function App() {
// Call the hook which returns, current value and the toggler function
// Call the hook which returns the current value and the toggler function
const [isTextChanged, setIsTextChanged] = useToggle();

return (
Expand All @@ -59,8 +59,8 @@ const useToggle = (initialState: boolean = false): [boolean, any] => {
// Initialize the state
const [state, setState] = useState<boolean>(initialState);

// Define and memorize toggler function in case we pass down the comopnent,
// This function change the boolean value to it's opposite value
// Define and memoize the toggler function in case we pass down the component,
// This function change the boolean value to its opposite value
const toggle = useCallback((): void => setState(state => !state), []);

return [state, toggle]
Expand Down