wehooks
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

web-hooks

Common hooks to use inside browser react apps

Hooks ideas

Here I will put some ideas

useStoredState

useStoreText

This is a hook which allows to use local storage as a context provider. So you can reuse state across components without any provider code!

Component1.tsx

import React from 'react';
import { useStoreText } from '@/hooks/useStoreText';
import { MyStorage } from '@/__sandbox__/models';

export const Component1 = () => {
    const [testStoreText,setTestStoreText] = useStoreText('myValue', 'bbbbb');

    return (
        <div>
            <div>useStoreText somewhere the value is loaded from local storage</div>
            <div>{testStoreText}</div>
            <button onClick={() => setTestStoreText(new Date().toLocaleString())}>
        </div>
    );
};

Component2.tsx

import React from 'react';
import { useStoreText } from '@/hooks/useStoreText';
import { MyStorage } from '@/__sandbox__/models';

export const Component2 = () => {
    const [testStoreText] = useStoreText('myValue');

    return (
        <div>
            <div>useStoreText in other place it will be updated when the 1st one will be</div>
            <div>{testStoreText}</div>
        </div>
    );
};

/wehooks/

    Package Sidebar

    Install

    npm i wehooks

    Weekly Downloads

    4

    Version

    0.0.1

    License

    MIT

    Unpacked Size

    24.4 kB

    Total Files

    19

    Last publish

    Collaborators

    • aexol-office