casesandberg / react-color

:art: Color Pickers from Sketch, Photoshop, Chrome, Github, Twitter & more
http://casesandberg.github.io/react-color/
MIT License
12.04k stars 921 forks source link

Cannot read property 'r' of undefined #689

Open japgolly opened 4 years ago

japgolly commented 4 years ago

This looks fantastic on the demo page but is anyone using this outside of the demo?

The simplest thing possible doesn't work for me:

  render() {
    return <ChromePicker />;
  }

fails with

Chrome.js:96 Uncaught TypeError: Cannot read property 'r' of undefined
    at Chrome (Chrome.js:96)

which checks out looking at the source.

The documentation doesn't help. It says it should work. In fact hardly any of the documentation seems correct...

If anyone's using this for real surely surely you must have come across these issues, or have somehow avoided them. Pls help?

Pushplaybang commented 4 years ago

hey there,

using the ChromePicker just fine parsing in a hex val.

<ChromePicker color={color} onChangeComplete={handleChange} />

where color is something like '#f7f7f7`

japgolly commented 4 years ago

Hey, thanks for the response! I was starting to feel like I'm going crazy or doing something very wrong.

Can I ask what version of React you're using?

Pushplaybang commented 4 years ago

sure:

"react": "^16.12.0",
"react-color": "^2.18.0",
"react-dom": "^16.12.0",
casesandberg commented 4 years ago

Were you able to get this working? I cant seem to reproduce this error on my end.

edsel77 commented 4 years ago

vue-color's color variable object key 'r' is searching for the valid value I've got the same error and fixed it by assigning the correct response data

Incorrect assignment: this.color= response

Correct assignment: this.color= response.MyRGBColorData

R4VANG3R commented 4 years ago

Were you able to get this working? I cant seem to reproduce this error on my end.

The ChromePicker will work but any of the helper components will give this error. See: https://codesandbox.io/s/stoic-microservice-pmlli?file=/src/App.js

GalaxySystem commented 4 years ago

I don't know why either, i met this problem when i used Saturation.

GalaxySystem commented 4 years ago

It's the same as using Saturation, it receives a string | rgbColor | hslColor, but if i set a string value, it get wrong with that error

flahtorres commented 1 year ago

Same problem here, I'm using react-color with @material-ui/core (the 4 version of mui) and the Saturation component

I was getting the error "TypeError: Cannot read property 'h' of undefined". So I look into the code and there's a line that is trying to find the h s and l properityies inside the props object

background: 'hsl(' + this.props.hsl.h + ',100%, 50%)',

I had tried to force pass the props to Saturation, but I got "Uncaught TypeError: Cannot add property updater, object is not extensible"

`

`

my handleChangeColor is a useCallback to parse the color inside the event to a hex+a notation. I had tryied to use rgba too, but same error

currentColor is the hex+a state color