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-webassembly/pages/index.js
2018-09-17 21:48:06 +02:00

25 lines
649 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)