rsnext/examples/with-unstated/pages/index.js
tylim 81cfea7d90 improve Unstated example so that it can shares state when switching pages (#5822)
* add new example

* update gitignore

* fix lint

* fix linting

* fix linting again

* update unstated example

* remove unsued var

* update readme
2018-12-05 11:32:45 +01:00

37 lines
906 B
JavaScript

import React from 'react'
import Link from 'next/link'
import { Subscribe } from 'unstated'
import { ClockContainer, CounterContainer } from '../containers'
import { Clock, Counter } from '../components'
class Index extends React.Component {
componentWillUnmount () {
clearInterval(this.timer)
}
render () {
return (
<Subscribe to={[ClockContainer, CounterContainer]}>
{
(clock, counter) => {
this.timer = clock.interval
return (
<div>
<Link href='/about'>
<button>
go to About
</button>
</Link>
<div>
<Clock clock={clock} />
<Counter counter={counter} />
</div>
</div>
)
}
}
</Subscribe>
)
}
}
export default Index