@line/create-liff-app
Version:
Start developing LIFF application with a simple CLI command.
34 lines (29 loc) • 965 B
JavaScript
import "../styles/globals.css";
import { useState, useEffect } from "react";
function MyApp({ Component, pageProps }) {
const [liffObject, setLiffObject] = useState(null);
const [liffError, setLiffError] = useState(null);
// Execute liff.init() when the app is initialized
useEffect(() => {
// to avoid `window is not defined` error
import("@line/liff").then((liff) => {
console.log("LIFF init...");
liff
.init({ liffId: process.env.NEXT_PUBLIC_LIFF_ID })
.then(() => {
console.log("LIFF init succeeded.");
setLiffObject(liff);
})
.catch((error) => {
console.log("LIFF init failed.");
setLiffError(error.toString());
});
});
}, []);
// Provide `liff` object and `liffError` object
// to page component as property
pageProps.liff = liffObject;
pageProps.liffError = liffError;
return <Component {...pageProps} />;
}
export default MyApp;