As far as the transmitted array is concerned, I believe that this is really background information, and there is no real flaw for this in terms of performance.
It’s better to make the length available on Child Contextsuch that you don’t have to manually pass the props through a bunch of components that don’t necessarily care.
it also seems that it would be more clear to pass only the length, since the component does not care about real objects in the array.
, , , 5- :
var React = require('react');
var ChildWhoDoesntNeedProps = require('./firstChild');
var Parent = React.createClass({
childContextTypes: {
arrayLen: React.PropTypes.number
},
getChildContext: function () {
return {
arrayLen: this.state.theArray.length
};
},
render: function () {
return (
<div>
<h1>Hello World</h1>
<ChildWhoDoesntNeedProps />
</div>
);
}
});
module.exports = Parent;
, ChildWhoDoesntNeedProps
var React = require('react')
var ArrayLengthReader = React.createClass({
contextTypes: {
arrayLen: React.PropTypes.number.isRequired
},
render: function () {
return (
<div>
The array length is: {this.context.arrayLen}
</div>
);
}
});
module.exports = ArrayLengthReader;