1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-context-api/pages/index.js

26 lines
715 B
JavaScript
Raw Normal View History

import React, { Component } from 'react'
import Link from 'next/link'
/* 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>
<h1>HOME</h1>
<p>Counter: {count}</p>
<button onClick={increase}>Increase</button>
<button onClick={decrease}>Decrease</button>
<p><Link href='/about'>
<a>About</a>
</Link></p>
</div>
)}
</CounterConsumer>
)
}
}