ReactJs warning: Mutating `style` is deprecated. Consider cloning it beforehand

前端 未结 2 1289
被撕碎了的回忆
被撕碎了的回忆 2021-01-27 00:58

I am receving the following warning:

inWarning: `div` was passed a style object that has previously been mutated. Mutating `style` is deprecated. Consider clonin         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-27 01:42

    You are cloning the selectedColor object but not the style object.

    do something as follows

    var clone = Object.assign({}, this.state.selectedColor);
    this.styles.previewColorHover.backgroundColor = clone.hex
    var style = {};
    style["previewColorHover"] = {backgroundColor : clone.hex}
    

    and use the style object in the div as

提交回复
热议问题