Files
react.dev/examples/context/consumer-cached-function-as-a-child.js
2018-03-29 09:15:30 -07:00

16 lines
368 B
JavaScript

class Example extends React.Component {
// This method will be called when the context value changes,
// But not when the props value changes!
renderValue = value => {
return (
<div>
Context value:{value}. Props value:{this.props.counter}
</div>
);
};
render() {
return <Ctx.Consumer>{this.renderValue}</Ctx.Consumer>;
}
}