From 281d1b59f8c06c4c039eae7be1b709da3be424d6 Mon Sep 17 00:00:00 2001 From: Arthur Denner Date: Sun, 11 Jul 2021 10:08:42 +0200 Subject: [PATCH 1/2] fix: pass current color to setColor when used as a function --- src/useColor.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/useColor.ts b/src/useColor.ts index 989c409..1f41b9d 100644 --- a/src/useColor.ts +++ b/src/useColor.ts @@ -25,8 +25,7 @@ export const useColor = ( | ((prevColor: RgbaObject) => ColorInput), ) => { if (typeof nextColor === 'function') { - const nextColorInput = nextColor(color.rgba) - setColor(parseColor(nextColorInput)) + setColor((currentColor) => parseColor(nextColor(currentColor.rgba))) return } setColor(parseColor(nextColor, config)) From 498819a392660fc2ecd1a6659d975a247e778d78 Mon Sep 17 00:00:00 2001 From: Arthur Denner Date: Sun, 11 Jul 2021 10:10:48 +0200 Subject: [PATCH 2/2] docs: use color.strings to access parsed values --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0987dc5..2c4d62f 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,10 @@ color.rgb // { r: 34, g: 114, b: 235 } color.rgba // { r: 34, g: 114, b: 235, a: 1 } const [color] = useColor('rgb(34, 114, 235)') -color.string.hex // #2272eb +color.strings.hex // #2272eb const [color] = useColor('rgba(34, 114, 235, 0.5)') -color.string.hex // #2272eb80 +color.strings.hex // #2272eb80 color.rgb // { r: 34, g: 114, b: 235 } color.rgba // { r: 34, g: 114, b: 235, a: 0.5 } ``` @@ -45,9 +45,9 @@ color.rgba // { r: 34, g: 114, b: 235, a: 0.5 } ```tsx const [color] = useColor({ r: 255, g: 255, b: 255 }) -color.string.hex // '#ffffff' -color.string.rgb // 'rgb(255, 255, 255)' -color.string.rgba // 'rgb(255, 255, 255, 1)' +color.strings.hex // '#ffffff' +color.strings.rgb // 'rgb(255, 255, 255)' +color.strings.rgba // 'rgb(255, 255, 255, 1)' ``` ### Stringify Options