Skip to content

Commit 8bbe3ea

Browse files
committed
packages and contexts
1 parent 9520862 commit 8bbe3ea

3 files changed

Lines changed: 232 additions & 49 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React, { createContext, useContext, useState, ReactNode } from 'react';
2+
3+
type UserContextType = {
4+
name: string;
5+
setName: (name: string) => void;
6+
};
7+
8+
const UserContext = createContext<UserContextType | undefined>(undefined);
9+
10+
export const UserProvider = ({ children }: { children: ReactNode }) => {
11+
const [name, setName] = useState('');
12+
13+
return (
14+
<UserContext.Provider value={{ name, setName }}>
15+
{children}
16+
</UserContext.Provider>
17+
);
18+
};
19+
20+
export const useUser = () => {
21+
const context = useContext(UserContext);
22+
if (!context) throw new Error('useUser must be used within a UserProvider');
23+
return context;
24+
};

KonditionExpo/package-lock.json

Lines changed: 205 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)