If am to pass an object to a child component via the components props, does this object get cloned or does it simply pass a reference to the original object?
For example in my App.js
I am importing a JSON object ENTRY_DATA
. I am then passing that object via props to my child components (or in this case, routes). Am I saving on memory by doing this or would it be the same as if I was to import ENTRY_DATA
on each component?
import React, { Component } from 'react';
import { withRouter, Route } from 'react-router-dom'
import ENTRY_DATA from './../../entry_data.json';
import Register from '../Register/Register';
import Categories from '../Categories/Categories';
import Category from '../Category/Category';
import Entry from '../Entry/Entry';
class App extends Component {
render() {
return (
<div className="app" >
<main>
<Route exact path="/" component={Register} />
<Route exact path='/categories' render={(props) => (
<Categories {...props} categories={ENTRY_DATA} />
)}/>
<Route exact path='/categories/:category' render={(props) => (
<Category {...props} categories={ENTRY_DATA} />
)}/>
<Route exact path='/categories/:category/:entry' render={(props) => (
<Entry {...props} categories={ENTRY_DATA} />
)}/>
</main>
</div>
);
}
}
export default withRouter(App);
If ENTRY_DATA
is 5kb's, And I am passing it to 3 different components, does that mean I end up with 20kb's worth of ENTRY_DATA
or do they all reference the one 5kb ENTRY_DATA
?