I have a component that receives a prop that looks like this:
const styles = {
font: {
size: {
value: \'22\',
unit: \'px\'
This is your mistake
setStyle({
...style,
font: { align: event.target.value } // This code replace the font object
});
To preserve the all font
object values, you can do like this
const onChange = (event) => {
const s = {...style};
s.font.align = event.target.value;
setStyle(s);
}
Or
const onChange = (event) => {
setStyle({
...style,
font: {
...style.font, // Spread the font object to preserve all values
align: event.target.value
}
});
}