Created
March 18, 2019 22:51
-
-
Save ajcrites/75963c4304939820bb0b15c61591292d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -1,20 +1,25 @@ | |
-import React, { useState, createContext } from 'react'; | |
+import React, { useReducer, createContext, Dispatch } from 'react'; | |
import { HexInput } from '~/HexInput'; | |
import { RgbaInput } from '~/RgbaInput'; | |
+import { colorReducer } from '~/colorReducer'; | |
interface ColorContextProps { | |
hex: string; | |
rgba: number[]; | |
+ | |
+ dispatch: Dispatch<Action>; | |
}; | |
const ColorContext = createContext<ColorContextProps>({} as any); | |
export const ColorToolApp = () => { | |
- const [hex, setHex] = useState(''); | |
- const [rgba, setRgba] = useState(['', '', '', '']); | |
+ const [{ hex, rgba }, dispatch] = useReducer(colorReducer, { | |
+ hex: '', | |
+ rgba: [0, 0, 0, 0], | |
+ }); | |
const state: ColorContextProps = { | |
- hex, rgba, setHex, setRgba, | |
+ hex, rgba, dispatch, | |
}; | |
return ( |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment