mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
1f64082c03
* Add with-context-api example * Change next dependency to canary and fix CounterProvider import
21 lines
573 B
JavaScript
21 lines
573 B
JavaScript
import React, { Component } from 'react'
|
|
/* First we import the consumer */
|
|
import { CounterConsumer } from '../components/CounterProvider'
|
|
|
|
export default class index extends Component {
|
|
render () {
|
|
return (
|
|
/* Then we use our context through render props */
|
|
<CounterConsumer>
|
|
{({ count, increase, decrease }) => (
|
|
<div>
|
|
<p>Counter: {count}</p>
|
|
<button onClick={increase}>Increase</button>
|
|
<button onClick={decrease}>Decrease</button>
|
|
</div>
|
|
)}
|
|
</CounterConsumer>
|
|
)
|
|
}
|
|
}
|