Skip to content

Commit

Permalink
use await
Browse files Browse the repository at this point in the history
  • Loading branch information
timarney committed Jun 21, 2022
1 parent 8c4ec8d commit 8565225
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,18 @@ function useEyeDropperApi({ onChange }) {
}
}, [isEyeDropperApiSupported]);

const openEyeDropper = useCallback(() => {
const openEyeDropper = useCallback(async () => {
if (!eyeDropper.current || !isEyeDropperApiSupported) {
return;
}

eyeDropper.current
.open()
.then((result) => {
onChange(getSolidFromHex(result.sRGBHex.substring(1)).color);
})
.catch((e) => {
//eslint-disable-next-line no-console -- Surface error for debugging.
console.log(e.message);
});
try {
const { sRGBHex } = await eyeDropper.current.open();
onChange(getSolidFromHex(sRGBHex.substring(1)).color);
} catch (e) {
//eslint-disable-next-line no-console -- Surface error for debugging.
console.log(e.message);
};
}, [eyeDropper, isEyeDropperApiSupported, onChange]);

return { isEyeDropperApiSupported, openEyeDropper };
Expand Down

0 comments on commit 8565225

Please sign in to comment.