1.0.1 • Published 3 years ago

@vanpariyar/hooks v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

My Personalized Custom Hooks that i am using for React and Gutenberg Wordpress Editor.

Purpose for using this

  • No need to understand Comeplex redux for the small piece of the task.
  • easily share the component data with diffrent components
  • Work Like same as useState

Package Link

use

import { useLocalStorage, useSessionStorage } from '@vanpariyar/hooks'
import { useEffect } from 'react'


const functionalComponent = () => {
    const[ newsArticles, setNewsArticles ] = useSessionStorage( 'newsArticles', InitialValue );

    // OR

    const[ newsArticles, setNewsArticles ] = useLocalStorage( 'newsArticles', InitialValue );

    useEffect(()=>{
        if( newsArticles ) { return };
        setArticles( [ 1, 2, 3 ] )
    },[])
    
}

export default functionalComponent;

than in any compnent

import { useLocalStorage, useSessionStorage } from '@vanpariyar/hooks'

const otherFunctionalComponent = () => {
    const[ newsArticles, setNewsArticles ] = useSessionStorage( 'newsArticles', InitialValue );

    // OR

    const[ newsArticles, setNewsArticles ] = useLocalStorage( 'newsArticles', InitialValue );

    console.log( newsArticles );
}

export default otherFunctionalComponent;

Credits

webdev simplified: The useLocalStorage hook is inspired by them Thank you.

1.0.1

3 years ago

1.0.0

3 years ago