Brian Vaughn
7 years ago
3 changed files with 43 additions and 1 deletions
@ -0,0 +1,15 @@ |
|||||
|
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>; |
||||
|
} |
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
class Example extends React.Component { |
||||
|
render() { |
||||
|
// The inline function will be called when the context value changes,
|
||||
|
// And when the props value changes!
|
||||
|
return ( |
||||
|
<Ctx.Consumer> |
||||
|
{value => ( |
||||
|
<div> |
||||
|
Context value:{value}. Props value:{this.props.counter} |
||||
|
</div> |
||||
|
)} |
||||
|
</Ctx.Consumer> |
||||
|
); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue