react-native-persist-context
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

react-native-persist-context

A library to help your context being persisted in your react native apps

Installation

npm install react-native-persist-context @react-native-async-storage/async-storage

Usage

import usePersist from 'react-native-persist-context';

// ...

const AppContext = createContext({} as InformationContextType);

export default function AppProvider({children}) {
    const [data, setData, clear] = usePersist(
        'userData',
        {
            user: {
                name: 'Hubert Ryan',
                twitter: 'hubertryanoff',
                tapedin: 'hubertryan'
            }
        }
    );

    const handleUserData = (newUserData) => {
        setData({
            ...data,
            user: newUserData
        });
    };

    return (
        <AppContext.Provider
            value={{
                ...data,
                handleUserData
            }}
        >
            {children}
        </AppContext.Provider>
  );
}

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

Package Sidebar

Install

npm i react-native-persist-context

Weekly Downloads

2

Version

0.2.0

License

MIT

Unpacked Size

31.3 kB

Total Files

28

Last publish

Collaborators

  • hubertryan