rsnext/examples/with-webassembly/pages/index.js
Joe Haddad 18a9c7e371
Improve linting rules to catch more errors (#9374)
* Update `packages/`

* Update examples

* Update tests

* Update bench

* Update top level files

* Fix build

* trigger
2019-11-10 19:24:53 -08:00

26 lines
674 B
JavaScript

import { withRouter } from 'next/router'
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
return props => <div>{rustModule.add_one(props.number)}</div>
},
})
const Page = ({ router: { query } }) => {
const number = parseInt(query.number || 30)
return (
<div>
<RustComponent number={number} />
<Link href={`/?number=${number + 1}`}>
<a>+</a>
</Link>
</div>
)
}
export default withRouter(Page)