React-color: CustomPicker does not work in modern React

Created on 26 Aug 2020  路  9Comments  路  Source: casesandberg/react-color

Seems like there is a problem with CustomPicker higher-order component in React 16+. Can CustomPicker be used in React v16?

Works with React v15.6.1
https://codesandbox.io/s/custom-picker-old-react-forked-o9770

Does not work with React v16.12.0
https://codesandbox.io/s/custom-picker-new-react-ur2z4

Most helpful comment

Fix provided in #791

All 9 comments

Same problem here, would love to have a hot-fix on this.

Commenting getDerivedStateFromProps in ColorWrap.js has fixed the problem for me
image

but I am not fully aware of the root cause, there is one related thread, where it mentioned that there is a dev-dependencies on an older version of react

Root cause is #662 , componentWillReceiveProps can't be changed to getDerivedStateFromProps just like that.

React docs

Note that this method is fired on every render, regardless of the cause. This is in contrast to UNSAFE_componentWillReceiveProps, which only fires when the parent causes a re-render and not as a result of a local setState.

v2.17.3 works for me

@hzhu @tazhel if you listen onChange and provide the changed colour to colorpicker through color props then it is working fine, Here is the working codeSandBox Project forked from your one.
image

basically it is working in a controlled mode, not in AutoControlled mode or It is kind od providing your own CustomWrapper over color-picker instead of using ColorWrap

Seems like there is a problem with CustomPicker higher-order component in React 16+. Can CustomPicker be used in React v16?

Works with React v15.6.1
https://codesandbox.io/s/custom-picker-old-react-forked-o9770

Does not work with React v16.12.0
https://codesandbox.io/s/custom-picker-new-react-ur2z4

Any solutions on this one?

The same problem with ChromePicker and SketchPicker.

"react": "16.13.1",
"react-dom": "16.13.1",
"react-color": "2.19.3"

Any update on this thread ?

Fix provided in #791

Was this page helpful?
0 / 5 - 0 ratings

Related issues

imsheng picture imsheng  路  6Comments

foreverpinetree picture foreverpinetree  路  3Comments

louh picture louh  路  4Comments

rpearce picture rpearce  路  4Comments

jimmylinh picture jimmylinh  路  4Comments