File size: 824 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
---
id: api-onChange
title: onChange
---
Pass a function to call every time the color is changed. Use this to store the color in the state of a parent component or to make other transformations.
Keep in mind this is called on drag events that can happen quite frequently. If you just need to get the color once use `onChangeComplete`.
```
import React from 'react';
import { SwatchesPicker } from 'react-color';
class Component extends React.Component {
handleChange(color, event) {
// color = {
// hex: '#333',
// rgb: {
// r: 51,
// g: 51,
// b: 51,
// a: 1,
// },
// hsl: {
// h: 0,
// s: 0,
// l: .20,
// a: 1,
// },
// }
}
render() {
return <SwatchesPicker onChange={ this.handleChange } />;
}
}
```
|