Mapped props with leading _
Internally, we use these mapped props to track updates and prevent component re-renders. For every state value you observe, you are effectively asking for re-renders when that changes. However, sometimes you want to have a read-only property. Re-rendering in that situation is a wasted expense. If you want a property to be read-only, you can prefix it with an _
.
NOTE:
In the future, this will be managed behind the scenes through the babel transform.
wrap(Component, {
mapStateToProps() {
return {
foo: 'foo',
_bar: 'bar', // Component will not re-render when this changes
}
}
});