A react context provider for LIFF (LINE Front-end Framework)
npm install react-liff


A react context provider for LIFF (LINE Front-end Framework)
- React v18.0 or later
- React Native is not supported.
- LIFF SDK version >=2.19.1
1. Create your React application development environment.
- e.g. npx create-react-app app-name
2. Add react-liff to your app dependencies.
``sh`
npm i --save @line/liff react-liff
# or
yarn add @line/liff react-liff
react-liff
3. Import to your app and use it!
- An example of src/App.js
`javascript
import React, { useEffect, useState } from 'react';
import { useLiff } from 'react-liff';
import './App.css';
const App = () => {
const [displayName, setDisplayName] = useState('');
const { error, isLoggedIn, isReady, liff } = useLiff();
useEffect(() => {
if (!isLoggedIn) return;
(async () => {
const profile = await liff.getProfile();
setDisplayName(profile.displayName);
})();
}, [liff, isLoggedIn]);
const showDisplayName = () => {
if (error) return
Something is wrong.
;Loading...
; if (!isLoggedIn) {
return (
);
}
return (
<>
Welcome to the react-liff demo app, {displayName}!
return (
export default App;
`
- An example of src/index.js
`javascript
import React from 'react';
import ReactDOM from 'react-dom';
import { LiffProvider } from 'react-liff';
import './index.css';
import App from './App';
const liffId = process.env.REACT_APP_LINE_LIFF_ID;
ReactDOM.render(
document.getElementById('root')
);
`
1. Create your React application development environment.
- e.g. npx create-react-app app-namereact-liff
2. Add to your app dependencies.`
sh`
npm i --save react-liff
# or
yarn add react-liff
index.html
3. Update to load LIFF SDK`
- https://developers.line.biz/en/docs/liff/developing-liff-apps/#developing-a-liff-app
diff`
+
react-liff
4. Import to your app and use it!
- liffId: string, requiredwithLoginOnExternalBrowser
- The ID of your LIFF application.
- : boolean, optionalliff.init()
- See the API reference of . https://developers.line.biz/en/reference/liff/#initialize-liff-app-argumentsplugins
- : Array, optional[pluginInstance, pluginOption]
- List of LIFF plugin instances.
- If you need to pass option to plugin, you can use the list of tuple .callback
- : (liff: Liff) => Promise, optionalliff.init()
- Callback function that fires after has been succeeded.
- error: unknown (is LiffError | undefined in many cases)liff.init()
- Returns an error if was failed.isLoggedIn
- : booleanisReady
- Returns whether the user is logged in.
- : booleantrue
- Returns after liff.init() has successfully completed. Otherwise, returns false.liff
- : Liff`
- Returns liff object.