Created
November 11, 2022 07:34
-
-
Save hamzamu/26cf9960531e0b0d361a7350e0f0f74f to your computer and use it in GitHub Desktop.
Next.js with DDP client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Head from 'next/head'; | |
import { useState, useEffect } from 'react'; | |
import 'tailwindcss/tailwind.css'; | |
import DashboardLayout from '../dashboard/layout'; | |
// import you astroid. | |
import { createClass } from 'asteroid'; | |
function MyApp({ Component, pageProps }) { | |
// Import and Initiate your DDP connection within React's useEffect | |
useEffect(() => { | |
const Asteroid = createClass(); | |
// Connect to a Meteor backend | |
const asteroid = new Asteroid({ | |
endpoint: 'ws://localhost:3033/websocket', | |
}); | |
// Now you can call methods or subscribe to a collection | |
asteroid | |
.call('helloddp') | |
.then((result) => { | |
console.log('Success'); | |
console.log(result); | |
}) | |
.catch((error) => { | |
console.log('Error'); | |
console.error(error); | |
}); | |
}, []); | |
return ( | |
<> | |
<Head> | |
<title>Salvia-kit Dashboard v4 Next.js</title> | |
</Head> | |
<DashboardLayout> | |
<Component {...pageProps} /> | |
</DashboardLayout> | |
</> | |
); | |
} | |
export default MyApp; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment