-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.js
39 lines (30 loc) · 1.18 KB
/
state.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React, { useState } from "react";
import { createContainer } from "unstated-next";
import { formatColor } from "util/color";
const useTextColor = (initialState = { r: 0, g: 0, b: 0 }) => {
const [color, setColor] = useState(initialState);
return { color, formattedColor: formatColor(color), setColor };
};
export const TextColor = createContainer(useTextColor);
const useBackgroundColor = (initialState = { r: 255, g: 255, b: 255 }) => {
const [color, setColor] = useState(initialState);
return { color, formattedColor: formatColor(color), setColor };
};
export const BackgroundColor = createContainer(useBackgroundColor);
const usePageTitle = (
initialTitle = ["Camden Phalen"],
initialDone = false
) => {
const [pageTitle, setPageTitle] = useState(initialTitle);
const [isDone, setIsDone] = useState(initialDone);
return { pageTitle, setPageTitle, isDone, setIsDone };
};
export const PageTitle = createContainer(usePageTitle);
const StateProvider = ({ children }) => (
<TextColor.Provider>
<BackgroundColor.Provider>
<PageTitle.Provider>{children}</PageTitle.Provider>
</BackgroundColor.Provider>
</TextColor.Provider>
);
export default StateProvider;