#1
Hello. I have the code:
class Component extends React.Component {
    render() {
        this.props.nested.prop = this.props.parse.nested.prop;
        return <div>Component</div>;
    }
    componentDidMount() {
        console.log(this.props.nested.prop);
    }
}
Component.defaultProps = {
    nested: {
        prop: "default",
    },
};
const obj1 = {
    nested: {
        prop: "obj1",
    },
};
const obj2 = {
    nested: {
        prop: "obj2",
    },
};
class Application extends React.Component {
    render() {
        return (
            <div>
                <Component parse={obj1} />
                <Component parse={obj2} />
            </div>
        );
    }
}
React.render(<Application />, document.getElementById("app"));
// console output:
// "obj2"
// "obj2"
Why do I get 1 variable reference for 2 separate components instead of 2 instances of nested.prop for every component? Why this.props saves only last setted value for all instances of the component after mounting? Is it a normal behavior? I think the correct behavior is having different property values for different instances.
P.S. I have tested this code here.
#2
jimfb has been answered:
"You are mutating the default prop that was passed in. The line this.props.nested.prop = this.props.parse.nested.prop; is illegal."
My next question:
How to pass nested properties without a manual mutation of props?
For example:
Component.defaultProps = {
    nested: {
        prop1: "default",
        prop2: "default",
    },
};
const props = {
    nested: {
        prop1: "value",
    },
};
let component = <Component {...props} />;
Guide to the code above JSX spread attribute feature just override props.nested and I lose default nested properties. But it is not that I need.
How about to implements a recursive traversing of nested objects in stage of JSX spread attributes parsing?
Or Is there some useful pattern for this case?
 
     
     
    