-
Notifications
You must be signed in to change notification settings - Fork 922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CustomPicker does not work in modern React #754
Comments
Same problem here, would love to have a hot-fix on this. |
Commenting 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 ,
v2.17.3 works for me |
@hzhu @tazhel if you listen 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 |
|
…f react. - Replaced getDerivedStateFromProps with componentDidUpdate and put a check on color input props before updating color state . Fixed casesandberg#754
Any solutions on this one? |
The same problem with ChromePicker and SketchPicker.
|
Any update on this thread ? |
The issue is that ColorWrap HOC manages color state but at the same time accepts "color" prop which affects the state in getDerivedStateFromProps. Because getDerivedStateFromProps is called every render, it always replaces state without acutal checking if the color property was changed. In the demo https://codesandbox.io/s/custom-picker-new-react-ur2z4 mentioned in casesandberg#754 the component has initial value 'orange' - it will derive to state every render. I added a step to check if property was changed to prevent resetting internal state. But to be honest I suggest to change the API of the component to avoid confusion. In the example ```tsx <MyPicker color="orange" onChangeComplete={handleColorChange} /> ``` Color prop is always passed so it should never change it by its own. If the intention is to provide initial value for the component, I think we should add 'defaultValue' property to indicate that it will be used only once.
Fix provided in #791 |
Seems like there is a problem with
CustomPicker
higher-order component in React 16+. CanCustomPicker
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
The text was updated successfully, but these errors were encountered: