There might be wrong usage in the `examples/basic-with-react-hooks`, that will cause the <Alpha/> component not working.
xiaoyuze88 opened this issue · comments
When I try it out the demo using SketchPicker
, I found out that the Alpha
handle is not working.
After digging for a while I found the usage from the demo is wrong.
// In the demo
const [color, setColor] = useState();
const handleChange = color => setColor(color);
return (
<div className="App">
<SketchPicker color={color} onChangeComplete={handleChange} />
</div>
);
After adding some logs in the source code(helpers/color.js -> toState()), you can see the onChange
callback pass a color object to the setColor, which includes a param named hex
, and that will cause the toState
function to handle it as a pure hex, so the alpha is lost.
It should be used like this:
// In the demo
const [color, setColor] = useState();
const handleChange = color => setColor(color.rgb);
return (
<div className="App">
<SketchPicker color={color} onChangeComplete={handleChange} />
</div>
);