2018-12-17 16:34:32 +00:00
|
|
|
import { withRouter } from 'next/router'
|
2018-09-17 19:48:06 +00:00
|
|
|
import dynamic from 'next/dynamic'
|
|
|
|
import Link from 'next/link'
|
|
|
|
|
|
|
|
const RustComponent = dynamic({
|
|
|
|
loader: async () => {
|
|
|
|
// Import the wasm module
|
|
|
|
const rustModule = await import('../add.wasm')
|
|
|
|
// Return a React component that calls the add_one method on the wasm module
|
2018-12-17 16:34:32 +00:00
|
|
|
return props => <div>{rustModule.add_one(props.number)}</div>
|
2018-09-17 19:48:06 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-12-17 16:34:32 +00:00
|
|
|
const Page = ({ router: { query } }) => {
|
2018-09-17 19:48:06 +00:00
|
|
|
const number = parseInt(query.number || 30)
|
2018-12-17 16:34:32 +00:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<RustComponent number={number} />
|
|
|
|
<Link href={`/?number=${number + 1}`}>
|
|
|
|
<a>+</a>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
)
|
2018-09-17 19:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default withRouter(Page)
|