React hooks: How do I update state on a nested object with useState()?

前端 未结 6 825
一个人的身影
一个人的身影 2021-02-08 13:43

I have a component that receives a prop that looks like this:

const styles = {
    font: {
        size: {
            value: \'22\',
            unit: \'px\'
           


        
6条回答
  •  忘了有多久
    2021-02-08 13:51

    you can update the styles in this manner

    onChange={(event) => {
        const s = {...styles};
        s.font.align = event.target.value;
        setStyle(s);
        console.log(style);
    }}
    

提交回复
热议问题