Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Last active March 19, 2019 00:23
Show Gist options
  • Select an option

  • Save ajcrites/63eb2f1c394df5447fc4056156f4ceed to your computer and use it in GitHub Desktop.

Select an option

Save ajcrites/63eb2f1c394df5447fc4056156f4ceed to your computer and use it in GitHub Desktop.
import React, { useState, createContext } from 'react';
import { HexInput } from '~/HexInput';
import { RgbaInput } from '~/RgbaInput';
interface ColorContextProps {
hex: string;
rgba: number[];
setHex: (value) => void;
setRgba: (value) => void;
};
export const ColorContext = createContext<ColorContextProps>({} as any);
export const ColorToolApp = () => {
const [hex, setHex] = useState('');
const [rgba, setRgba] = useState(['', '', '', '']);
const state: ColorContextProps = {
hex, rgba, setHex, setRgba,
};
return (
<main>
<ColorContext.Provider value={state}>
<HexInput />
<RgbaInput />
</ColorContext.Provider>
</main>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment